【问题标题】:adding node app to aws将节点应用程序添加到 aws
【发布时间】:2018-08-19 04:32:45
【问题描述】:

我正在将我的节点应用程序添加到 aws,但它不会加载实际页面。我认为我的 server.js 文件有问题,因为如果我将锅炉节点应用程序和 ssh 加载到我的 aws 中并运行它,应用程序就可以工作。但是,当我运行我的连接超时或我收到类似的错误

events.js:183
  throw er; // Unhandled 'error' event
  ^
Error: listen EADDRINUSE :::3000
   at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at Server.setupListenHandle [as _listen2] (net.js:1355:14)
at listenInCluster (net.js:1396:12)
at Server.listen (net.js:1480:7)
    at Function.listen (/home/ubuntu/memory-box/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/home/ubuntu/memory-box/server.js:21:5)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3

我的 server.js 文件看起来像

var express = require('express'),
app = express(),
port = process.env.PORT || 3000,
mongoose = require('mongoose'),
Task = require('./api/models/memoryBoxModel'), //created model loading here
bodyParser = require('body-parser');
mongoose.Promise = global.Promise; mongoose.connect('mongodb://username:password@ds125402.mlab.com:25402/memorybox', { useNewUrlParser: true });

app.use('/uploads', express.static('uploads'))
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());


var routes = require('./api/routes/memoryBoxRoutes'); //importing route
routes(app); //register the route


app.listen(port);

app.use(function(req, res) {
// The snippet bellow helps to redirect and respond whenever a wrong 
route is entered on the site.
 res.status(404).send({url: req.originalUrl + ' not found'})
});

console.log('todo list RESTful API server started on: ' + port);

my aws set up is

【问题讨论】:

    标签: node.js amazon-web-services express


    【解决方案1】:

    您第一次尝试运行应用程序时,您正在使用的端口没有关闭,所以当您运行它时,该端口正在使用中。您可以关闭端口重试或更改端口。

    我建议你尝试使用 Nodemon。

    Nodemon 将监视我们的应用程序,并在我们看到任何文件发生更改时自动重新启动服务器。当应用程序自行关闭端口时。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-27
      • 2020-11-11
      • 2019-02-21
      • 2017-11-19
      • 2017-08-09
      • 2021-02-06
      相关资源
      最近更新 更多