Node.js Tutorial – 1


node.js (http://nodejs.org) starts to gain its popularity these days. It is a Javascript-based event-driven, non-blocking IO, lightweight Server side toolkit, which can be easily used to build e.g. web servers, scalable network applications, distributed job scheduler .  The javascript engine node.js is built on was from Google, the Javascript V8 engine. Therefore, the node.js is of high performance using Google’s excellent Javascript interpreter, which is also used in Google’s chrome browser. The partial reasons that Javascript V8 is highly-efficient are 1. some Javascript code are translated to machine assembly code. 2. Inline caching techniques are employed. Javascript is a powerful programming language that is dynamic, weekly-typed, prototype-based scripting language that is mostly used in client side, e.g. browser (embedded in HTML static pages).

The Javascript then can be both now used in Server side and Client side, as Javascript can be also used in some other areas for instance, the Windows Script Hosting, and it has been implemented by many browsers, it has been said that ‘Javascript is the future language’.

node.js is platform-independent, you can download the binary installer or source code from http://nodejs.org. The popular operating system such as Linux, Windows are supported.

After installation, you look for nodejs icon to start the console.

nodejs2 Node.js Tutorial - 1 code code library internet javascript network nodejs programming languages web programming

Under the prompt ‘>’, you can type command and receive immediate response, similar to other Shells, such as Python, Matlab. The console.log simply prints message to the standard output. The undefined means that the function does not return any value.

nodejs1 Node.js Tutorial - 1 code code library internet javascript network nodejs programming languages web programming

Of course, you can save Javascript code in a file and use command line node file.js to execute the code.

nodejs3 Node.js Tutorial - 1 code code library internet javascript network nodejs programming languages web programming

The above shows that full Javascript feature is supported, e.g. the closure.

1
2
3
4
var msg = "Hello, " + "World!";
(function() {
  console.log(msg);
})();
var msg = "Hello, " + "World!";
(function() {
  console.log(msg);
})();

So far, there is nothing useful yet, but the process of setting up node.js and executing the Javascript code is illustrated.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
460 words
Last Post: Codeforces: 268A. Games
Next Post: Node.js Tutorial – 2

The Permanent URL is: Node.js Tutorial – 1

Leave a Reply