Here's my current theory as to how node.js will work:
Obviously I've got something wrong, because I've been looking for a tutorial for the past hour or so which will teach me how to install it on my server - but they all seem to be focused on installing it locally.
Could someone give a dot-point rundown of how the final implementation will work?
You install it on a "server" as you would for any other machine -- with admin/root access via an installer or package manager.
Now, this assumes, by "server," you're referring to a computer. If, instead, you mean an existing "server application," such as Apache or IIS -- Node.js doesn't integrate directly with these. It primarily replaces them, allowing you to define the entire server application, from a rather low level, as a script.
Such a script can be found on the project's homepage:
This simple web server written in Node responds with "Hello World" for every request.
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/');
To run the server, put the code into a file
example.js
and execute it with thenode
program from the command line:% node example.js Server running at http://127.0.0.1:1337/
Beyond this example, you would want to inspect the req.method
and req.url
, typically via a router or web framework, to determine how to respond. express
or compoundjs
would be good options to start with.
You can still use other server applications as an HTTP proxy for Node.js, passing traffic along. But Node.js will still be running separately. If you're using IIS, there's even iisnode which covers much of the setup for this.