node.js 无法使节点 js 在端口 3000 上工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26469492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't make node js working on port 3000
提问by arlindmusliu
I have already done the same process for getting node js up and running. But, after two months, doing the exact same steps, won't make it work. I need to set up node locally and I use mongodb as well. I have downloaded the latest versions of node js, mongodb and npm.
我已经完成了相同的过程来启动和运行 node js。但是,两个月后,执行完全相同的步骤,将无法正常工作。我需要在本地设置节点,我也使用 mongodb。我已经下载了最新版本的 node js、mongodb 和 npm。
I start the application with "node app.js" and the cursor moves to the new line and it won't say that it's listening on port 3000. This is my problem. I check the localhost:3000 on my browser but it says "This webpage is not available".
我用“node app.js”启动应用程序,光标移动到新行,它不会说它正在监听端口 3000。这是我的问题。我在浏览器上检查了 localhost:3000,但它显示“此网页不可用”。
When I do "netstat -a -b" it shows that node.exe has the local address 192.168.1.125:139. And just under it says "Can not obtain ownership information".
当我执行“netstat -a -b”时,它显示 node.exe 的本地地址为 192.168.1.125:139。就在它下面写着“无法获得所有权信息”。
My config file is:
我的配置文件是:
module.exports = {
development : {
db: {
host : 'mongodb://localhost/ekopanelen'
},
app: {
name: 'ekopanelen',
port: 3000
}
} };
My code for starting node is:
我的启动节点代码是:
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];
More code:
更多代码:
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;
Starting the 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);
});
采纳答案by jfriend00
Here's the code that starts my node.js server:
这是启动我的 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
You should be looking for that piece of code.
您应该寻找那段代码。

