The origin of the Node. Js

Node.js is the implementation of the No GUI, the back-end of Javascript, which can be improved hundreds of times by the V8 Javascript interpretation engine developed by Google. In some cases even comparable to code written in C (compared to Javascript that wasn’t optimized 10 years ago), Node.js is capable of extending functionality using C/C++ code (and perhaps WebAssamble instead) in addition to being able to write code in Javascript.

Javascript was once regarded as a toy language because it was developed with Lisp and other non-mainstream languages rather than Java or C, which were mature at that time. However, with the change of software development environment, although Lisp and other languages are less used, However, the ideas of Lisp and other non-mainstream languages at that time were praised by more people. However, the design architecture of Javascript made it easy to realize these development and writing concepts, so Javascript gradually gained the attention of many heavyweight enterprises. And with the development of Javascript, A number of Javascript features have migrated to other languages, most notably JSON, which was originally a Javascript output format for serializing data, much like PHP’s serialize serialize() function. There is less data redundancy, so it is slowly becoming the de facto data communication format for the industry. The popular lamda function, for example, is almost naturally supported by Javascript, because everything in Javascript is an object, including functions, so it comes naturally to implement lamda functions without even having to change any of the underlying Javascript code. Languages like Java weren’t supported until Java 8.

Because the advantages of Javascript are constantly explored by people, Javascript gradually began to be not satisfied with the development of the front section, because under the continuous improvement, front-end development has become unusually simple compared with the previous, while the back end development was controlled by Java, C# and other large languages, the development is still as slow as ever. When convenient Javascript didn’t work, some people wanted to port Javascript to the back end. Fortunately, Google’s V8 interpretation engine had been open source for a long time, and it could be used to create applications that could match the performance of native applications, hence Node.js.

Which version of Node.js should you learn

Node. Js development has been a period of time, the first version is conservative, function follow up is just like toothpaste, bit by bit ES6 draft have been published at the time, but the Node. Js, it took a year of time to achieve less than ten characteristics, and these features to promote the efficiency of almost nothing for development, so insiders protested, In protest at node.js’s slow development, they created a separate IO. Js project that essentially cloned the Node.js source files, but aggressively added many ES6 features. It wasn’t long before the Node.js team realized how slow they were. (As an aside, Google led a bad example of randomly updating Chrome to the point where it became a version king, and this bad example affected other software as well, including Node.js), From node.js 0. X to Node.js 4. X, the release span was quite large, and at the same time they added the IO. Version numbers are updated once a month or even twice a month. Basically, the ES6 specification node.js is implemented.

If you’ve never worked with Javascript before, you should go straight to node.js version 10.x, which implements the entire ES6 specification, which is a nice syntactic icing for Javascript. You don’t have to learn arcane prototype chains, you don’t have to be confused by this, everything is as natural as any other language, and you can enjoy Javascript’s high degree of freedom

How do I install Node.js

The Windows platform

If you’re running Windows, go to the node.js website and download the installation package

Mac

You can download it from the MAC OS website or install it on BREW

Linux platform

Linux users can also download it directly from the official website, or install it through software management software such as APT or YUM. However, the official version of the installation package may be relatively late. I recommend you to install an official source on Github, which can be installed on the latest version of Node.js

The above installation is used if you have never installed Node.js before. If you already have an older version of Node.js installed, you can use NPM to install different versions of Node.js

After installation

After installing Node.js, there are two things you need to do if you want to play smoothly. The first is to install YARN, using the NPM command line

sudo npm install -g yarn
Copy the code

After the installation, when you want to use NPM command can replace with yarn command, this command is used in place of NPM, because the yarn will cache the third-party libraries, when your project to reference a third party libraries, it will first check the local computer is installed above the third-party libraries, if present, Create a link to the file directly, thus reducing the time to re-download the third-party library.

The second thing is that you may want to lower the NPM installation source, because the NPM installation source server in foreign countries, the speed is often very slow, and now there are many mirror sites in China, the original installation source conversion to the domestic installation source, can greatly speed up the download speed

Start experimenting with Node.js

When you’re done, write Hello World! the

// index.js
console.log('Hello World! ')
Copy the code

Then run the command node index.js to see the output