What you are asking is very broad in term of question . Let me give the idea how it work.
Coming from PHP things seem a bit confusing as there is no
index.php, but a start-script needs to be executed to fire up the
server npm start.
So in node.js we have a file by which we start our node server and that we decide what we want . mostly people use app.js , server.js , index.js
when you run npm start , that means you would have package.json in the folder that file have written start: node app.js . And when you run npm start , it get fire .
How is this done in production? Are there pre-run scripts?
NODE_ENV=production npm start , you can access this in node code like this
process.env.NODE_ENV . in this way you can add dev,qa tag for each environment .
I will recommend you to have a look in
http://pm2.keymetrics.io/
What if the server closes for some reason, how do I get it back up automatically without having connection problems for the clients?
For that reason you can look at https://nodejs.org/api/cluster.html
You can manage the crash thread and then open another thread as node is single thread.
Also you can manage the node.js all type of error By this . This make node.js catch all exception and error
https://nodejs.org/api/process.html
process.on
does it also mean someone alwasy has to go to domain.com:3000?
No. You can take any port you want . 80,8080 whatever . I will recommend to use nginx in front of node.js application . But for less compatibility go for simple node application .
for example:-
var http = require('http');
var port = 3000 ; // take any 80, 8080
http.createServer(function (request, response) {
response.writeHead(200, {
'Content-Type': 'text/plain',
'Access-Control-Allow-Origin' : '*'
});
response.end('Hello World\n');
}).listen(port);
Hope this help .