Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Node.js Tutorial

Node.js Tutorial

Simply put, Node.js is JavaScript that runs on the server.

Node.js is a platform built on the Chrome JavaScript runtime.

Node.js is an event-driven, I/O-based server-side JavaScript environment built on Google's V8 engine; the V8 engine executes JavaScript very quickly and performs extremely well.


Who should read this tutorial?

If you are a front-end programmer who does not know dynamic programming languages such as PHP, Python, or Ruby, and you want to create your own service, then Node.js is an excellent choice.

Node.js is JavaScript that runs on the server; if you are familiar with JavaScript, you will find it very easy to learn Node.js.

Of course, if you are a backend programmer and want to deploy some high-performance services, then learning Node.js is also a very good choice.


What you need to know before studying this tutorial

Before continuing with this tutorial, you should understand some basic computer programming terms. If you have studied programming languages such as Javascript, PHP, or Java, it will help you understand Node.js programming more quickly.


Node.js Features


Application Scenarios of Node.js


Version in use

We can use the following command to check the current Node version:


$ node -v
v4.4.3

**Note:** There may be differences between different versions.


The first Node.js program: Hello World!

Script mode

The following is our first Node.js program:

Example

console.log("Hello World");

Run Example »

Save the file with the name helloworld.js, and execute it with the node command:

node helloworld.js

After the program runs, if everything is normal, Hello World will be output in the terminal.

Interactive mode

Open the terminal, type node to enter the interactive command mode, where you can enter a code statement and have it executed and display the result immediately, for example:


$ node
> console.log('Hello World!');
Hello World!

Gif Example Demonstration

Next, we demonstrate the example operations with a Gif image: