JavaScript’s popularity is obvious. And solutions such as node.js have a big influence on this. For a longer time, we can see and hear a lot about this technology.
We also use node from some time, and… we can do really cool things, so for sure it’s something worthy of attention. And finally I have some time to write about node.js.
JavaScript has a bright future, but also I think we can consider node.js as a mandatory skill.
node.js — introduction
Node.js is a platform that allows to run JavaScript code. It is built on V8 JS engine — the same is used e.g. in Google Chrome.
And so what? Well, this JavaScript code we can run outside the browser! And thanks to the API and node.js modules we have a lot possibilities, typical for server-side technologies, such as file I/O, database communication or socket.io.
Node provides us with a powerful set of tools!
To install extensions we use NPM:
https://www.npmjs.com/
Node.js is a programming environment designed to create highly scalable web applications, especially web servers written in JavaScript.
Node.js allows you to create applications using asynchronous event-driven I/O system. Obviously, this is an open source project.
OK, enough talking — let’s code!
How to use node.js
Working with node.js can start in the blink of an eye. We need node and npm tools — installed and available in command line.
For this, simply grab and install the version of node.js for our system:
http://nodejs.org/download/
Having node.js installed, you can run the test code.
The simplest example — run node in command line and write:
console.log("Hello node!");
// -> Hello node!
A better idea would be to save the code in the file, e.g. test1.js. Then we can call:
$node test1.js
// -> Hello node!
We can also run the script in debug mode:
$ node debug test.js
The console.log function is the main way to display messages for the user (developer).