Node.js uses WebSocket-based push technology in real-time web applications. How revolutionary does this mean? Well, after more than 20 years of stateless interactions based on stateless request-return mechanisms, we finally have real-time, two-way connected web applications. Both the client and the server can initiate communication and exchange data freely. . In stark contrast to the traditional web response model, the client always actively initiates communication and the server passively returns. Furthermore, these are based on open web components (HTML, CSS and JS) running on standard port 80.
One might argue that we've been using Flash and Java Applets for years - but in reality, these methods just use the network to pass data to a sandbox environment on the client. They all run in isolation and often operate on non-standard ports that require additional permissions and the like.
With its unique advantages, Node.js has now played a key role in the products of many famous companies.
The main idea of Node.js is to use non-blocking, event-driven I/O operations to remain lightweight and efficient when processing data-intensive real-time applications across distributed devices. This sounds a bit convoluted.
What it really means is that Node.js is not a silver bullet platform that is going to dominate the world of web development. Rather, it is a platform that meets a specific need. You definitely don’t want to use Node.js to do CPU-intensive operations. In fact, using it for heavy calculations is equivalent to discarding almost all the advantages of Node. Where Node really shines is in building high-performance, highly scalable Internet applications - because it can handle large and high-throughput concurrent connections.
Basic system installation
Node can run perfectly on Linux, Macintosh, and Solaris systems. Ubuntu is quite suitable for Linux distributions. This is why we are trying to install Node.js on ubuntu 15.04. Of course, the same steps can also be used to install on 14.04.
1) System resources
The basic system resources required by Node.js depend on your architectural needs. We will conduct this tutorial on a server with 1GB of memory, 1GHz processor and 10GB of disk space. Minimal installation is enough and no web server or database server is required.
2) System update
Before we install Node.js, it is recommended that you update the system to the latest patches and upgrade packages, so please log in to the system and use the super user to run the following command:
# apt-get update
3) Install dependencies
Node.js only requires some basic system and software capabilities on your server, such as 'make', 'gcc' and 'wget'. If you haven’t installed them yet, run the following command to install them:
# apt-get install python gcc make g++ wget
Download the latest version of Node JS v4.0.0
Visit the link Node JS Download Page Download the source code.
Copy the link to the latest source code, and then use wget to download it. The command is as follows:
# wget https://nodejs.org/download/rc/v4.0.0-rc.1/node-v4.0.0-rc.1.tar.gz
After the download is complete, use the command tar to decompress:
# tar -zxvf node-v4.0.0-rc.1.tar.gz
Install Node JS v4.0.0
Now you can start compiling Node.js using the downloaded source code. Before starting compilation, you need to switch to the directory where the source code is decompressed on the ubuntu server and run the configure script to configure the source code.
root@ubuntu-15:~/node-v4.0.0-rc.1# ./configure
Now run the command 'make install' to compile and install Node.js:
root@ubuntu-15:~/node-v4.0.0-rc.1# make install
The make command will take a few minutes to complete the compilation, please wait quietly for a while.
Verify Node.js installation
Once the compilation task is completed, we can start to verify that the installation worked OK. We run the following command to confirm the Node.js version.
root@ubuntu-15:~# node -v
v4.0.0-pre
Running node without parameters on the command line will enter REPL (Read-Eval-Print-Loop, read-execution-output-loop) mode. It has a simplified version of the emacs line editor through which you can interactively Run JS and view the results.
Write test program
We can also write a very simple terminal program to test whether the installation is successful and works normally. To do this, we will create a "test.js" file containing the following code, as follows:
root@ubuntu-15:~# vim test.js var util = require("util"); console.log("Hello! This is a Node Test Program"); :wq!
Now to run the above program, run the following command on the command line.
root@ubuntu-15:~# node test.js
Running the above program in an environment with Node JS successfully installed will get the output shown in the picture above on the screen. This program loads the class "util" into the variable "util", and then uses the object "util" to run the terminal task. , the console.log command is similar to cout
Conclusion
That's all. If you have just started using Node.js to develop applications, I hope this article can give you an overview of Node.js by installing and running Node.js on ubuntu. Finally, we can assume that we can expect significant performance improvements with Node JS v4.0.0.