Common URL:
node. JS Rookie Tutorial: http://www.runoob.com/nodejs/nodejs-tutorial.html
nodejs.org//node.js Official website
Npmjs.com//
Github.com//node.js
stackoverflow.com//Technical Quiz Community
One. node. JS Basic Knowledge
node. JS is written in the C + + language.
Simply put, node. JS is the JavaScript that runs 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, based on the Google V8 engine , the V8 engine executes JavaScript very quickly and with great performance.
Referring to JS will think of the browser "1" Interactive component "2" Asynchronous request
Rely on browser people JavaScript engine parsing page JS code.
node. js
"1". Can parse the JS code (no browser security level restrictions)
"2". Provides system-level API (management "3" network communication for "1" file read-write "2" processes)
Why learn about node. js
1. It's very hot 2. It's strong.
Two. Node. JS Course Introduction 1. Install node. js "1". Version of node. js
"2" Windows/linux System installs node. js
Installation is more cumbersome. The environment needs to be prepared first.
Reference Video: https://www.imooc.com/video/6692
"3" Mac installs node. js//To see if the installation was successful
Reference Video: https://www.imooc.com/video/6693
Can be installed with brew. Brew Install node
command Line input: n 0.10.22 can download a fixed version.
command Line Input: N, press the up and down keys to toggle the version of node.
See if node. js//xcode-select-p is installed
The file directory above indicates that it is installed, otherwise it is not installed.
Mac installation can be found in: http://www.cnblogs.com/kaixinyufeng/p/9031662.html
2. Simple example:
See also: http://www.runoob.com/nodejs/nodejs-http-server.html
Development tools: Vscode
environmental preparation; NODE.JS/NPM
Project schema: Create a folder (NODEJS), create a subfolder (HttpRequest), create a JS file-"Populate the HTTP request content."
The command line enters the HttpRequest folder directory. Node Httpserver.js starts the node. JS server.
Browser address bar access: http://127.0.0.1:8888/
Show Results:
Nodejs Server Code:
1 /**2 * node. JS components:3 * Step1: Introduction of require module: Use require instructions to load node. JS Modules4 * STEP2: Create server: Server can listen for client requests, similar to HTTP server such as Apache/nginx5 * STEP3: Receive request and Response request: The server is easy to create, the client can use the browser or terminal to send HTTP requests, the server receives the request data and returns the response data6 */7 varHTTP = require ('http');//node. js comes with the HTTP module and assigns it to the HTTP variable8 9 //the HTTP module provides the function Createserver, which returns an object that has a method called Listen that specifies the port number that the HTTP server listens on. TenHttp.createserver (function (request, response) {//callback Function (Request/response) One A //Send HTTP Header - //HTTP Status value: 200:ok - //content Type: Text/plain theResponse.writehead ( $, {'Content-type':'Text/plain'}); - - //Send response data "Hello NodeJs" -Response.End ('Hello nodejs\n'); +}). Listen (8888); - + //The terminal prints the following information AConsole.log ('Server running at http://127.0.0.1:8888/');
View Code
The above code can be rewritten as:
1 //Example 2:2 varServer =http.createserver (function (request, response) {//callback Function (Request/response)3 4 //Send HTTP Header5 //HTTP Status value: 200:ok6 //content Type: Text/plain7Response.writehead ( $, {'Content-type':'Text/plain'});8 9 //Send response data "Hello World"TenResponse.End ('Hello world\n'); One }); A -Server.listen (9999); - the //The terminal prints the following information -Console.log ('Server running at http://127.0.0.1:9999/');
View Code
When the terminal starts the node. JS Service, it displays:
Address bar Access: http://127.0.0.1:9999/display results: Hello World
3. Console Simple Application
"1". Open Chrome's console and you can enter the command you want to execute directly. Enter to display the results.
The console can enter window/document directly to view its properties
"2". Command line terminal: Enter node into the node. JS environment to enter the command to execute directly. You can also print the results.
4. Node. JS's module and COMMONJS specification "1". Module and package management tools
"2" COMMONJS specification
"3". Mutual promotion of norm and realization
"4". Module classification
Note: The module and the file are one by one corresponding to each other.
Depending on the type, the Introduction module can be
(1). File path Introduction
(2). Module name Reference (introduction of non-core module, module name will be introduced into the corresponding path)
Non-core modules include: NPM Install/colleague-created local module
"5". Process of the module
Example: There is currently a school (school), Class (Class), class with teachers (teacher) and students (student),
The school/class/teacher/student is three different modules respectively. class to introduce the teacher/student module. School to introduce class module
STEP1: Create Package School
STEP2: Create student Student.js
STEP3: Creating a teacher Teacher.js
STEP4: Create class Class.js and introduce Teacher.js & Student.js
STEP5: Create a startup portal. Index.js, introduce class module, and call Add method Add teacher & Student
STEP6: The console starts the node service (preferred to go to the school folder below.) Input command node Index.js)
Show Results:
School is also exposed to the outside. The
5. The node. JS API uses
node. JS Core module: http/url/querystring module
"1". URL URLs parsing
Video: https://www.imooc.com/video/6710
URL Document directory: https://nodejs.org/dist/latest-v8.x/docs/api/url.html
"2" QueryString parameter Processing tool (serialization/deserialization/escape/reversal semantics)
https://www.imooc.com/video/6711//Video address
https://nodejs.org/dist/latest-v8.x/docs/api/querystring.html//doc Address
001/node.js (MOOC)