Simply put, Node.js is JavaScript running on the server.
Node.js is a platform built on the Chrome JavaScript runtime.
Node.js is an event-driven I/O server-side JavaScript environment. It is based on Google's V8 engine. The V8 engine executes Javascript very quickly and has very good performance.
Who is suitable to read this tutorial?
If you are a front-end programmer who doesn't understand dynamic programming languages like PHP, Python, or Java, and then you want to create your own services, Node.js is a very good choice.
Node.js is JavaScript running on the server. If you are familiar with Javascript, you will easily 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.
You need to know before studying this tutorial
Before continuing this tutorial, you should understand some basic computer programming terms. If you have learned programming languages such as Javascript, PHP, and Java, it will help you understand Node.js programming faster.
Node.js installation and configuration
Here, I will demonstrate how to install Node.js on Windows and Linux. The software installation version takes 0.12.0 as an example.
Node.js official installation package and source code download address: http://nodejs.org/download/
Depending on the different platform, you need to select the required Node.js installation package.
Note: Node.js on Linux requires Python 2.6 or 2.7 to install, and it is not recommended to install Python 3.0 or above.
Install Node.js on Windows
Windows installation package (.msi):
Download it from the official download address provided above.
Demo environment:
Operating system: Windows 8.1 Enterprise x64
Node.js version: 0.12.0
Installation steps:
Step 1: Double-click the downloaded installation package "node-v0.12.0-x64.msi" to display the welcome interface, as shown below:
Step 2: Click Next to display the license agreement page of Node.js:
Step 3: Check "I accept the terms in the License Agreement" to agree to the license agreement, and click Next, and the following interface appears:
Step 4: The default installation path of Node.js is "C:/Program Files/nodejs/". You can modify it. Here I changed it to D disk. Click Next. The installation mode and module selection interface will appear:
Step 5: Here I directly default Next to Next, ready to install:
Step 6: After confirming that it is correct, click Install to start the installation:
Step 7: After half a minute, the installation is completed and click Finish:
Step 8: Configure environment variables:
By default, after Node.js is installed, the directory path of node.exe will be automatically configured in the system's path environment variable. However, after you complete the installation, you may enter node under the dos command to indicate an error.
When I opened the system environment variables, I found that it was indeed configured, but I couldn’t see the nodejs configuration when running "set path" under dos, that is a matter of character. . Just restart the computer and reload it.
You can also delete the automatic configuration and add it manually. as follows:
Open Computer Properties-Advanced-Environment Variables and find the path variable in the system variable list:
Click "Edit" and add the nodejs installation directory at the end:
Step 9: Check whether the installation is successful:
Click Start-Run-cmd, open dos, enter "node --version" to check Node.js version:
If it is displayed normally, then OK and the installation is complete!
Install Node.js on Linux
Ubuntu source code installation
In the following section, we will introduce the installation of Node.js under Ubuntu Linux. Other Linux systems, such as Centos, etc., are installed as follows.
Get the Node.js source code on Github, or you can download it on the official website:
After completing the download, change the source code package name to 'node'.
Modify directory permissions:
Create a compiled file using './configure'.
Compiled: make.
Complete the installation: make install.
Finally, we enter the 'node --version' command to check whether Node.js is installed successfully.
Ubuntu apt-get command installation
The command format is as follows:
The code copy is as follows:
sudo apt-get install nodejs
sudo apt-get install npm
Install nodejs under centOS
1. To download the source code , you need to download the latest Nodejs version at http://nodejs.org/. This article takes v0.12.0 as an example:
The code copy is as follows:
cd /usr/local/src/
wget http://nodejs.org/dist/v0.12.0/node-v0.12.0.tar.gz
2. Decompress the source code:
Copy the code as follows: tar zxvf node-v0.12.0.tar.gz
3. Compile and install:
The code copy is as follows:
cd node-v0.12.0
./configure --prefix=/usr/local/node/0.12.0
Make
make install
4. Configure NODE_HOME and enter profile to edit environment variables:
Copy the code as follows: vim /etc/profile
Set nodejs environment variables and add the following content on the export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL line:
The code copy is as follows:
#set for nodejs
export NODE_HOME=/usr/local/node/0.12.0
export PATH=$NODE_HOME/bin:$PATH
:wq save and exit, compile /etc/profile to make the configuration take effect
Copy the code as follows: 1 source /etc/profile
Verify that the installation configuration is successful
Copy the code as follows: node -v
Output v0.12.0 means the configuration is successful.
npm module installation path
Copy the code as follows: /usr/local/node/0.12.0/lib/node_modules/
The above is the entire content of this article’s introduction, installation and configuration. We will continue to update this series in the future, hoping it will be helpful to everyone.