The company recently recruit a return from Shenzhen "front-end great God." Soon after, the great God is a man who loves to toss. I chatted with him a few words, chat to JS, he strongly recommended to me node. js.
The name of node. JS I have also heard, a superficial impression, that this is a JavaScript back-end interpreter. JavaScript can do the back end, that's really the thing that blew the sky off. Give a chestnut, json he is no longer use what analytic tool class. This has to be said to be JavaScript, the anti-human (I have always thought JavaScript grammar anti-human) language, and the second spring glow.
However, the company's development plans have recently been busy. I've never had a quiet heart to learn more about node. js. Today seldom fell idle, then got to do JS.
First step: Install
A journey begins with a journey. To do node well, you have to install node first. I use the system is Ubuntu Linux, first used apt-get search, indeed there is a packet of node. But, with a curious heart, I still went to node. js
's official website has gone.
http://nodejs.org/
Online blog, most of the use of the source package is compiled installation. This behavior is really good, but when I install a software, there are often compile problems. Fortunately, the node. JS Official web site provides a compiled binary file. After downloading, unzip to the/usr/local/folder.
Configuration:
$ vim/etc/profile
Open the file and add it at the end:
Export Path=/usr/local/node/bin: $PATH
Export Node_path=/usr/local/node:/usr/local/node/lib/node_modules
Step Two: Learn what
node. JS is also a JS, so grammar or something, you don't have to learn. Unless you've never even learned JavaScript. The most important point is to use the library. This must be used to npm,npm what is it? If you have developed Python, then you must know the two tools, Pip and Easy_install. They are used to install the Python library, and node. JS is installed using NPM. Network installation, so it's important to use a good image address. Domestic network, because some people know the reason, is not stable, so we recommend you use the mirror address of Japan.
Step three: Write something.
People who write code often learn a new language from "hello,world! "Start (if you are not, sorry we are not in an era of). Wrote a line of code with node. js.
Console.log (' hello,world! ');
This line of code can see a lot of things. First, instead of using a "print" or "printf" keyword, use the log () method of the Console object (console objects). This is a more thorough object-oriented approach, and you can fully understand that the line of code is to print a single line of logs on the console (log is a logging method in many languages).
Fourth step: About event-driven
In the development process, the person who has written the front desk will not be unfamiliar with the event. Onclick,onchange,onsubmit and so on, node. JS promotes this event-driven spirit. You first in front of a JS code, the onclick event of the JS code, is not only executed when clicked?
The same applies to node. js in the background, where the code of the anonymous function is executed when something happens. For example, the code for the data operation can be set to be executed only when the database connected event occurs.
The so-called asynchronous IO is also taking advantage of this. Io is a time-consuming operation, so in the traditional language in order to let the program in the IO waiting, can also do something else, the use of people familiar with the multi-threading, concurrent programming. Multithreading, I can only say that whether it is coding or learning is quite laborious.
The asynchronous IO of node. js is good, but it's a bit difficult for programmers like us who write java,php,c to have no thought of turning corners.
Introduction to the "node. JS Development Guide", the book is very short, only 180 pages, read it effortlessly.