Lets get started with 'Hello world' example
1| I use nodeclipse, a plugin from marketplace for Eclipse IDE.
2| Create a Nodejs project and copy the below snippet.
var http = require('http');
http.createServer(function handler(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1335, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1335/');
OR|
var http = require('http');
http.createServer(function handler(request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('Hello World\n');
response.end();
}).listen(1335, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1335/');
OUTPUT |
3| To stop the server, use Eclipse IDE, Run > Debug
4| Right-click and select Terminate option from the list.
5| Now, re-run the snippet.
1| I use nodeclipse, a plugin from marketplace for Eclipse IDE.
2| Create a Nodejs project and copy the below snippet.
Snippet
var http = require('http');
http.createServer(function handler(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1335, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1335/');
OR|
var http = require('http');
http.createServer(function handler(request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('Hello World\n');
response.end();
}).listen(1335, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1335/');
OUTPUT |
3| To stop the server, use Eclipse IDE, Run > Debug
4| Right-click and select Terminate option from the list.
5| Now, re-run the snippet.

No comments:
Post a Comment