Answer the question
In order to leave comments, you need to log in
Run hello world on nodejs?
I do the following code on the server:
var n = 80;
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n'+n);
}).listen(n);
console.log('Server running at '+n);
Server running at 80
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1042:14)
at listen (net.js:1064:10)
at Server.listen (net.js:1138:5)
at Object.<anonymous> (/var/wwwdomen/data/www/domen.ru/file.js:7:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
var n = 8080;
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n'+n);
}).listen(n);
console.log('Server running at '+n);
Answer the question
In order to leave comments, you need to log in
In the first option, the port is busy and it throws an exception that you should catch somewhere, but you don't.
To start on a specific domain, either use a dedicated IP address for the domain, or proxy through nginx. Couldn't find any other solutions by quick googling.
Turn off Apache and start the server on port 80. (or turn on nginx and proxy to node)
As an option in Apache, you can redirect port 80 to the desired domain for the desired domain. For example node server is running on port 3000:
<VirtualHost node.example.com:80>
ServerName node.example.com
ProxyPreserveHost On
ProxyPass / http://localhost:3000/
</VirtualHost>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question