Can't make node js working on port 3000

2019-06-28 07:35发布

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.

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".

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".

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);
});

1条回答
混吃等死
2楼-- · 2019-06-28 08:00

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.

查看更多
登录 后发表回答