node. js Brief
Nodejs is a JavaScript runtime, the interpreter is written in C + +, based on the ChromeV8 engine, the event-driven, non-blocking I/O model. This series currently refers to the node. JS website, the Web Scott's node. JS Foundation, the "node is learned to use" Turing series, as well as possible online open resources.
The Nodejs Package Manager is a NPM package that is written by someone else.
Nodejs provides built-in objects such as fs,http to manipulate disk files and build servers.
Features: single-threaded, event-driven, asynchronous non-blocking I/O models.
node. JS Installation
The official website installs node. js and comes with NPM.
Install Git on your website.
Open a git bash or command-line tool, and the input node-v and NPM-V versions show that the installation is successful.
Build a Web server
Open node. JS Official website https://nodejs.org/en/, in the About column there is a piece of code, copied to our written server.js file. The code is as follows:
1Const HTTP = require (' http ');//Loading HTTP Modules2 3const hostname = ' 127.0.0.1 ';//Host Address4Const PORT = 1337;//Port number5 6Http.createserver ((req, res) = = {//Create Web server 200 Success7Res.writehead, {' Content-type ': ' Text/plain ' });8Res.end (' Hello node.js\n ');9}). Listen (port, hostname, () = {TenConsole.log (' Server running at http://${hostname}:${port}/'); One});
The code to build the Web server is already written, and the Web server is open below:
command-line tool, to the current folder, enter node Server.js, the visible server is turned on.
Now you can go to the browser to visit! Open Browser input 127.0.0.1, page display:
At this point, a Web server can handle the request rendering is complete!
If you save the file after modifying the 8th line of code output, the Refresh browser will not see the change. Because this differs from the browser script file, the server needs to be restarted.
In the command line tool CTRL + C can shut down the Web server, and then restart, then refresh the browser can see the changes.
Hello node. js to build a Web server