WebStorm:NodeJS Process以退出代码0结束

时间:2016-11-30 12:19:58

标签: node.js webstorm

我是NodeJS的新手,我从github下载了我的项目并安装了所有必需的NodeJS模块。并知道它只是显示

Webstorm控制台:

  

运行app.js

Process finished with exit code 0

并停止申请。

为什么它会停止。我无法访问localhost:3000。您的指导将受到高度赞赏。

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;

1 个答案:

答案 0 :(得分:9)

之前我遇到过这个问题,因为Webstorm控制台正在执行app.js而不是www

只需转到运行/调试配置面板(您可以从导航栏访问它):

Access Run/Debug Configurations from the Navigation Bar

导航至您的app.js 配置标签,然后将 JavaScript文件的路径更改为www文件。