Thursday, June 11, 2015

Working with Node.js server

server.js

var http = require('http');
http.createServer(function (req, res) {
var body="";
req.on('data', function (chunk) {
    body += chunk;
  });
  req.on('end', function () {
    console.log('POSTed: ' + body);
    res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('success');
  });

}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');


node server.js start the server

-------------
 Close the server

hello:tcps-service sandeepshabd$ ps aux | grep node

sandeepshabd    60569   0.0  0.0  2432772    672 s003  S+    1:16PM   0:00.00 grep node
sandeepshabd    60542   0.0  0.2  3067496  20056 s001  S+    1:11PM   0:00.18 node server.js


hello:tcps-service sandeepshabd$ kill -2 60542

No comments:

Post a Comment