I have seen lots of posts where people are recommending nginx or something similar as the front end web server for node.js.
Since node has the ability to create a web server, such as:
var http = require('http');
var static = require('node-static');
var file = new static.Server();
var url = require('url');
var index = require('./serverJS/index.js');
var login = require('./serverJS/login.js');
var admin_index = require('./serverJS/admin_index.js');
var admin_login = require('./serverJS/admin_login.js');
http.createServer(function (req, res) {
if (url.parse(req.url).pathname == '/index') {
index.serve(req, res);
} else if (url.parse(req.url).pathname == '/login') {
login.serve(req, res);
} else if (url.parse(req.url).pathname == '/admin/index') {
admin_index.serve(req, res);
} else if (url.parse(req.url).pathname == '/admin/login') {
admin_login.serve(req, res);
} else {
file.serve(req, res);
}
}).listen(9000 , '127.0.0.1' );
Q: In what case scenario would you need another web server in adition to node's?
A front-end Nginx would be more efficient at serving static assets.
A front-end Nginx would also be useful if you wanted to run multiple backend servers, like Node.js combined with Apache/PHP where Node.js serves some routes and Apache/PHP serves other routes.