问题描述
我已经完成了用于启动和运行Node js的相同过程.但是,两个月后,执行完全相同的步骤将无法正常工作.我需要在本地设置节点,我也使用mongodb.我已经下载了节点js,mongodb和npm的最新版本.
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 app.js"启动应用程序,并且光标移至新行,并且不会说它正在侦听端口3000.这是我的问题.我在浏览器上检查了localhost:3000,但显示此网页不可用".
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".
当我执行"netstat -a -b"时,它表明node.exe具有本地地址192.168.1.125:139.并在其下方显示无法获取所有权信息".
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".
我的配置文件是:
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];
更多代码:
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服务器的代码:
Here's the code that starts my node.js server:
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.
这篇关于无法使Node JS在端口3000上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!