Node.JS Express App无法在运行Ubuntu的AWS EC2实例上运行

时间:2015-06-06 15:02:54

标签: node.js express

我在过去的24小时内尝试过让我的快速应用程序运行。我已经按照教程,卸载然后重新安装了一切,仍然......没有骰子。

以下是设置M.E.A.N stack install wiki link我要安装的内容。

以下是我在命令提示符下的代码,告诉我在尝试运行应用程序时会发生什么

bitnami@ip-172-31-43-127:~/projects/sample$ ls
app.js  bin  node_modules  package.json  public  routes  views
bitnami@ip-172-31-43-127:~/projects/sample$ ./bin/www
nothing happens... it will just blink on this line forever♥
bitnami@ip-172-31-43-127:~/projects/sample$ DEBUG=new ./bin/www
same thing. it will blink forever an ⌂d ⌂♥
bitnami@ip-172-31-43-127:~/projects/sample$ DEBUG=new npm start
> sample@0.0.0 start /home/bitnami/projects/sample
> node ./bin/www
slightly different result... but the app is not running on localhost:3000♥
bitnami@ip-172-31-43-127:~/projects/sample$

我已尝试从StackOverflow实施此功能,但未修复

有人可以告诉我我做错了什么以及如何纠正这个问题?谢谢! :)

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 routes = require('./routes/index');
var users = require('./routes/users');

var app = express();

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

// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/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, 'public')));

app.use('/', routes);
app.use('/users', users);

// 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 handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
    app.use(function(err, req, res, next) {
        res.status(err.status || 500);
        res.render('error', {
            message: err.message,
            error: err
        });
    });
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
        message: err.message,
        error: {}
    });
});


module.exports = app;
var port = 3000;
app.listen(port, function() {
   console.log('Listening...');
});

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用普通的

npm start

您还可以在rm -rf bin/添加

底部键入app.js删除文件夹
app.listen(port, function() {
   console.log('Listening...');
});

然后运行

node app