I am new at node js and watching tutorials. But I am confused a bit about deploy node application.
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
This is a server file code. I am running with this command: % node example.js
This is Working on console...
But other platforms contains management area, (Php, IIS, Tomcat). www folder includes application files. Running service background. We change code and save it, but not restart service.
we specify everything on js file at node js platform. Run it from console. I could not understand running and deploying logic.
If I have linux server, or windows server, Should I open terminal and run application for each application? If I close terminal my application will stop?
In a classical PHP setup, the web server is separate from the application. The setup looks like this:
[browser/client] => [apache/mod_php] => [index.php]
With node, things are different, because the web server is part of the application. So your setup looks like this:
[browser/client] => [node server.js]
So, what does that mean for deployment?
Usually it means, you need a supervisor that starts your application and restarts it if it crashes. When you copied over a new version of your application, you simply use the restart mechanism of your supervisor.
Some supervisors even restart automatically when they notice the application's code changed, which is similar to PHP's change-and-reload workflow.
A small selection of supervisors you could use follows:
But there are many alternatives.
If you'd start your application from the terminal on the server, it would normally only run until you terminate the terminal session. When the server restarts (maybe because of a power or hardware failure), you have to restart your application manually. Because of that, the supervisor should be
Additionally, if you need
you most certainly need a reverse proxy in between your applications and the clients.
The setup would look like this:
/=> [apache/mod_php] => [index.php]
[browser/client] => [reverse proxy] => [node server1.js]
\=> [node server2.js]
Most web servers can also be configured to act like a reverse proxy. There are also specialized reverse proxies.
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