How to Get Start with Node.js

2014/5/312 min read
bookmark this
Responsive image

How to Create Simple Http Server using javascript Node.js

This blog is for people want to get start to learn Node.js, to build a simple HTTP Server.

I'm a .net developer, which mean like other .net developer using Javascript as Front-End language, back end using ASP.NET (MVC), IIS as sever side framework. Node.js to me is big surprise and I want to know how node.js create a HTTP Server.

At first, have to go to download by go to Node.js website.

Open Node.js command prompt, and go to a directory to create a JavaScript file, let's say server.js, but any name is fine. Following is a example you could add to the server.js, it will return hello world at the browser.

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/');

After this, at node.js command window, move to the folder which contains the server.js type

node server.js

node server.js Since the Port set at 1337, so go to your localhost:1337. You should be able to see HelloWorld.

...

At this point, simple HTTP Server by Node.js is finished.

Following are few links I found out very interesting to go more deeper. StackOverFlow - list of tutorials, videos, books, courses, blogs

  1. StackOverFlow - list of tutorials, videos, books, courses, blogs
  2. 7 Web Frameworks help you build better Node.js
  3. Interesting article, build desktop app with Node.js
  4. Huge list of modules could use for Node.js
  5. From code to deploy to cloud service, very detail document
  6. Beginner Web Frameworks Express.js for Node.js
  7. Express.js example List