Node.js Server start command and basic server code(Lesson 1)


Lesson 1: Node.js 

command to run server.js file in command line ubuntu

node server.js

//server.js file and code to write to start basic server at port 8888

var http = require(“http”);  //requiring http module provided by node.js

// calling http module create server method by its object

http.createServer(function(request, response) {

response.writeHead(200, {“Content-Type”: “text/plain”});
response.write(“Hello World”);
response.end();

console.log(‘Page requested at ‘ + new Date() + ‘, for ‘ + request.url); // just for displaying in console
}).listen(8888); // asiging port to server

 

OR you can write this code in another way

// calling http module create server method by its object

server= http.createServer(function(request, response) {

response.writeHead(200, {“Content-Type”: “text/plain”});

response.write(“Hello World”);

response.end();

console.log(‘Page requested at ‘ + new Date() + ‘, for ‘ + request.url); // just for displaying in console
})

server.listen(8888); // asiging port to server
Advertisements

I am Senior Software Engineer. I love reading, writing, sharing,developing, hiking, movies, trips, mountains, brooks, hills etc.

Posted in Nod.js

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

StackOverFlow
Categories
Archives
%d bloggers like this: