This is basically an addition to the answer from maerics, but since I want to add a code example I write another answer with additional information how to prevent security problems.
Usually web servers are started as root, because this is needed to bind on ports below 1024, but then they change the user they run under to an not privileged user.
You can do this with node.js using process.setuid("username")
.
The following example starts the server and then drop the root permissions to the user "www-data" after it bound itself to port 80 when started as root:
function StartServer() {
console.log("Starting server...");
// Initalizations such as reading the config file, etc.
server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
});
try {
server.listen(80, "0.0.0.0", function(){
process.setuid("www-data");
});
}
catch(err) {
console.error("Error: [%s] Call: [%s]", err.message, err.syscall);
process.exit(1);
}
}
sudo node sample.js
. That does the trick normally. – Hydrothorax