Node.JS basics

I loose lot of time for understand how to work Node.JS and I really don't understand why all the tutorials not speaks about this simple things, because is fucking basics and we most to understand it before the start. 

So lets start to understand right now.

Basics:

  • In a terminal (I use OS X) you need to create a folder for any your app – mkdir myapp
  • Well, now you have the folder, then you need to create an application file, for example app.js with this command: touch app.js

For testing we'll use simple example, in app.js file paste this code:

var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello node.js!');
});
server.listen(3000);
  • With a terminal enter on the folder myapp – cd myapp
  • Now, run application – node app.js

So, every time when you’ll closing a terminal, you app will be stoped (OS X). for use the app again you need to repeat this steps

  • With a terminal enter on the folder myapp – cd myapp
  • Now, run application – node app.js

Tanks for attention.