user3020640
user3020640

Reputation:

WebStorm: NodeJS Process finished with exit code 0

I am new to NodeJS, I have downloaded my project from github and installed all the required NodeJS modules. and know it just showing

Webstorm console:

run app.js

Process finished with exit code 0

and stops the application.

Why it is getting stop. I cannot access localhost:3000. Your guidance will be highly appreciated.

app.js

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var session = require('express-session');
var index = require('./routes/index');
var login = require('./routes/login');
var logout = require('./routes/logout');
var contact = require('./routes/contact');
var signup = require('./routes/signup');

var app = express();

var connection = require('express-myconnection');
var mysql = require('mysql');

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

app.use(session({
    secret: '123secret',
    proxy: true,
    resave: true,
    saveUninitialized: true
}));

app.use(
    connection(mysql, {

    host: 'localhost',
    user: 'proj',
    password: '123456',
    port: 3306, //port mysql
    database: 'projectnode'
}, 'request')
);

// uncomment after placing your favicon in /assets
//app.use(favicon(path.join(__dirname, 'assets', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'assets')));

app.use('/', index);
app.use('/login', login);
app.post('/login', login);
app.post('/signup', signup);
app.get('/contact', contact);
app.post('/contact', contact);
app.get('/logout', logout);


// catch 404 and forward to error handler
app.use(function (req, res, next) {
    var err = new Error('Not Found');
    err.status = 404;
    next(err);
});

// error handler
app.use(function (err, req, res, next) {
    // set locals, only providing error in development
    res.locals.message = err.message;
    res.locals.error = req.app.get('env') === 'development' ? err : {};

    // render the error page
    res.status(err.status || 500);
    res.render('error');
});

module.exports = app;

Upvotes: 5

Views: 10186

Answers (1)

Syed Daniyal Asif
Syed Daniyal Asif

Reputation: 736

I once had this problem before because the Webstorm console was executing app.js instead of www.

Just go to Run/Debug Configurations panel (You can access this from the Navigation Bar):

Access Run/Debug Configurations from the Navigation Bar

Navigate to your app.js Configuration tab and then change the path for the JavaScript file to your www file.

Upvotes: 11

Related Questions