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);
});
Here's the code that starts my node.js server:
You should be looking for that piece of code.