Системный Администратор




SiteMap


Node.js в Ubuntu Linux




$ sudo apt-get install -y npm


// Не помню нужно выполнять команду или нет.
$ sudo ln -s /usr/bin/nodejs /usr/bin/node



$ sudo npm install -g nodemon


$ vi web_server.js

var http = require('http');

var s = http.createServer(function (req, res){
	res.end("Hey, thanks for calling!");

});


s.listen(8080);



$ nodemon web_server.js

$ curl -X GET -i localhost:8080


============================

Усложняем скрипт

$ vi web_server.js

var http = require('http');


function request_handler (req, res){

        var body = "Hey, Thanks for calling!";
        var content_length = body.length;

        res.writeHead(200, {
                'Content-Type':   "text/plain",
                'Content-Length': content_length
        });

        res.write(body);
        res.end();
}

var s = http.createServer(request_handler);

s.listen(8080);

console.log('Servier running on port 8080');



$ nodemon web_server.js

$ curl -X GET -i localhost:8080


$ ps -ef | grep node


==============

$ node
> console.log(global)



http://nodejs.org/api/