Instructions for installing Node.js
Install Node.js internally
If you want to set up node.js environment on your personal computer, you must have 2 software on your computer. That is: 1) Text Editor (for example: Nodepad ++); 2) binary Nodejs installer.
Text Editor
It will be used to edit your program. For example, some Editor on Windows like Nodepad, vi or vim (on Linux) .
The file you create on your editor is called a source file (source file) and contains source code programs. Source files for Node.js are often named with the ".js" extension format.
Before starting this program, make sure you have a used text editro and experience in writing computer programs, storing files and executing it.
Install Node.js Runtime
Your source code is written in simple Javascript snippets. The Node.js interpreter will be used to compile and execute Javascript code.
Nodejs installed versions are available for 32-bit and 64-bit operating systems of Linux, Mac, Window .
The following section explains the steps to install Node.js binary on different operating systems.
Download Node.js
Download the latest version of Node.js from the Node.js Downloads page. At the time of this tutorial, the latest versions correspond to the following operating systems:
OSArchive nameWindows node-v0.12.0-x64.msi Linux node-v0.12.0-linux-x86.tar.gz Mac node-v0.12.0-darwin-x86.tar.gz SunOS node-v0.12.0-sunos-x86. tar.gzInstall Node.js on UNIX / Linux / Mac OS X, and SunOS
Based on the operating system architectures, downloading and extracting node-v0.12.0-osname.tar.gz in the / tm directory and finally extracting it into the / usr / local / nodejs directory. For example:
$ sudo apt-get install nodejs
Add / usr / local / nodejs / bin to the PATH environment variable:
OS ResultLuxux export PATH = / usr / local / nodejs / bin Mac export PATH = $ PATH: / usr / local / nodejs / bin FreeBSD export PATH = $ PATH: / usr / local / nodejs / binInstall Node.js on Windows
Use MSI file and follow the instructions that appear when installing Node.js. By default, the Node.js installer is stored at C: Program Filesnodejs.
Does the Node.js installation process succeed?
Create a js file named main.js on the computer (Windows or Linux) with the following code:
/* Hello, World! Vi du kiem tra cai dat node.js */ console . log ( "Hello, World!" )
Now execute main.js using the Node.js compiler to see the results:
$ node main . js
If everything succeeds, after compiling it will produce the result:
Hello, World!
According to Tutorialspoint
Last lesson: What is Node.js?
Next lesson: Module in Node.js
You should read it
May be interested
- Module in Node.jsnode.js uses the module architecture to simplify the creation of complex applications. the module is like libraries in c, c #, java ... each module contains a set of functional functions related to an object of module.
- Hello World program in Node.jsbefore creating the actual hello world application in node.js, see the main parts of the node.js program. a node.js program includes the following important sections.
- REPL Terminal in Node.jsrepl is an acronym for read eval print loop (understandably: reading - evaluating - printing - repeating) and it represents the computer environment like the console screen in the linux shell where you can type the command line and the system the system will return the results. node.js also has a repl environment.
- NPM in Node.jsprovides utilities to install node.js packages, version management and dependency management of packages in node.js.
- Callbacks concept in Node.jscallback has the same asynchronous property for a function. a callback function is called when completing a specific task. all node apis are written in the way of callback functions.
- Event Loop in Node.jsnode.js is a single thread application, but it supports concurrent processing through event definitions and callbacks. as all node.js apis are asynchronous and single threaded, it uses the async function to maintain concurrency. node.js uses the pattern observer.