Because the new job to do front-end, as the front-end small white and can learn as soon as possible, so choose the web of node. JS's Introductory tutorial. Blogs only do their own records of learning.
node. JS is essentially a JavaScript runtime environment. You can parse the JS code (without the restrictions of the browser security level) and provide the system-level API:
1. file reading and writing
2. Management of processes
3. Communication of the network
I. Installing node. JS (0.10.3x)
Install MSI on WIN10 and encounter permissions problems, the workaround is as follows:
1, the mouse moved to the lower left corner of the desktop (or directly: win+x key), command Prompt (administrator);
2. Input:msiexec/package + ' msi file path '(note the half-width character when input and the path cannot be Chinese name)
For example:
c:\windows\system32>msiexec/package G:\tool\TortoiseSVN-x64-1.8.9.msi
Installation is successful and the version number is displayed in CMD run node-v
Two. node. JS trial Run
Use the official example:
var http = require (' http ');
Http.createserver (function (req,res) {
Res.writehead ($, {' Content-type ': ' Text/plain '});
Res.end (' Hello world\n ');
}). Listen (1337, ' 127.0.0.1 ');
Console.log (' Server running at http://127.0.0.1:1337 ');
CMD start node server.js
Code parsing:
var http = require (' http '); ---> Load HTTP module, the responsibility is to create a Web server, and handle HTTP-related tasks, etc.
listen (1337, ' 127.0.0.1 '); --->listen allow the server to listen on port 1337
http.createserver (req,res) {--->createserver a Web server was created and passed in an anonymous callback function that is invoked once the listen has been requested. , the anonymous function has two parameters, req the request body, res response body.
req used to obtain request-related information, such as URL, request type, etc.
res used to tell the server what the response to this request
res.writehead ($, {' Content-type ': ' Text/plain '}); ---> The header of the response body, including the status code, response content type
node. js Getting Started Tutorial (a): Preparing