Hello I am trying to run my node.js webserver on port 80 on Ubuntu 12.04.2. This machine is a clean install and the only thing I have installed is, openssh-server nodejs and screen. When I run the node webservice on port 80, I can navigate to the browser and type in localhost and i will view my site. However when i try to access the site from a different machine i get timed out. I can however SSH and PING the machine. How can i setup ubuntu so that my node.js application is serving my website. The site works just fine when i host it on my laptop(windows 7) and a different laptop access the site by my ip address.
I do not want to run Apache or nginx. Is there anyway to do this?
//---ExpressJS
console.log('Initializing Express...');
var express = require('express');
var app = express();
//---Middleware: Allows cross-domain requests (CORS)
var allowCrossDomain = function(req, res, next){
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
}
///---MemoryStore
//var MemoryStore = express.session.MemoryStore;
//---App config
app.configure(function() {
var pub_dir = __dirname + '/public';
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.set("trust proxy", true);
app.use(express.favicon(__dirname+'/favicon.ico'));
app.use(express.compress());
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({secret: 'cogswell'}));
app.use(express.methodOverride());
app.use(allowCrossDomain);
app.use(app.router);
app.use(express.static(__dirname));
});
//---Start listening
var port = 80;
app.listen(port);
console.log('Webservice started on port: '+port);
UPDATE: the network has a massive firewall
Create NodeJS Serverjs file. Observe the last line where we specify listen(80). This will ensure that your NodeJS server runs on port 80. If you want to run NodeJS on different port, change 80 to your required port number (e.g 8080).
I know that Express apps default to port 3000.
Are you running as root? Or at least have permission to use port 80? On Linux systems you need special user privileges to use port 1024 or below. Try running as root using sudo node ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With