node.js – 无法使节点j在端口3000上运行

我已经完成了启动和运行节点js的相同过程.但是,经过两个月,完成相同的步骤,将无法使其发挥作用.我需要在本地设置节点,我也使用mongodb.我已经下载了最新版本的节点js,mongodb和npm.

我用“node app.js”启动应用程序,光标移动到新行,它不会说它正在侦听端口3000.这是我的问题.我在我的浏览器上检查了localhost:3000,但它说“此网页不可用”.

当我执行“netstat -a -b”时,它显示node.exe具有本地地址192.168.1.125:139.就在它下面说“无法获取所有权信息”.

我的配置文件是:

module.exports = {
development : {
    db: {
        host : 'mongodb://localhost/ekopanelen'
    },
    app: {
        name: 'ekopanelen',
        port: 3000
    }
}   };

我的起始节点代码是:

var express = require('express'), 
path = require('path'),
mongoose = require("mongoose"),
fs = require('fs'),
passport = require("passport"),
favicon = require('static-favicon'),
logger = require('morgan'),
cookieParser = require('cookie-parser'),
exhbs = require('express3-handlebars'),
session = require('express-session'),
bodyParser = require('body-parser');
var multer = require('multer');
/* set environment to development by default. */
var env = process.env.NODE_ENV || 'development',
config = require('./app/config')[env];

更多代码:

 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
      });
  }); }
 module.exports = app;

启动应用:

#!/usr/bin/env node
var debug = require('debug')('ekopanelen'),
app = require('../../app');
var env = process.env.NODE_ENV || 'development',
config = require('../config')[env];

 app.set('port', config.app.port || 3000);

/*
 * Start Server with port from node
*/
var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
 console.log('Express server listening on port ' + server.address().port);
});
最佳答案
这是启动我的node.js服务器的代码:

var express = require('express');
var app = express();
var server = app.listen(8081, function() {
    console.log(new Date().toISOString() + ": server started on port 8081");
});

// change the port number to whatever port number you want to use

你应该寻找那段代码.

转载注明原文:node.js – 无法使节点j在端口3000上运行 - 代码日志