First, the concept
node. JS is written in the C + + language using the Google Chrome browser specification engine. is essentially a JavaScript run environment
Nodejs not only can parse the JS code and there are no security level restrictions on the browser side
Some system-level APIs are also available, such as:
1. file reading and writing
2. Management of processes
3. Communication of the network
It's been a fire since 09.
Second, it's strong, and with the help of Nodejs, of course, it's not just
Node-webkit Appjs Similar applications: Allows developers to use web technologies, or HTML/CSS/JS, to develop cross-platform, desktop-based applications, all compatible with Mac,linux,windows
Jade: A template for efficient development and management of background HTML in combination with Nodejs
Ghost: A powerful and user-friendly open source blogging program
Grunt: is a JavaScript running tool for various tasks, through the integration of various plug-ins to complete such as: Style compilation, syntax detection, script compression merge, automated testing, shell script run
Document generation or image processing and other tasks, the Nodejs is also used in the module
Nodecast: First run on the PC, then start the mobile device, select a chrome-enabled application, and then you can map the mobile content to the computer, is equivalent to the computer as a streaming media to use
Log.io: Monitoring project log can be implemented in the browser
Pdfkit: Generating PDF documents
Haroopad: Is the markdown editor on Linux
Noduinoweb: Hardware hackers want to use Noduino Web pages to control open source hardware, which can combine software and hardware.
Nodeos: A friendly operating system based on NODEJS development
Other languages can do things nodejs can do even better
Recommended Learning Nodejs website 1, nodejs.org Nodejs's official site, often go to stroll around, pay attention to Nodejs update, bug fix. 2, npmjs.com module of the community, there are many great God written code, you can see the same function of the great God how to learn. 3, GitHub-should know, this is not much to say. 4, stackoverflow.com technical solution community.
For version issues with Nodejs
Even digits are stable version cardinality is non-stable version
Second, install Nodejs under Windows
First download a tool git bash can execute git commands, use the experience better, compare for beginners for Nodejs
According to the process do not do a detailed answer, according to their own needs of self-configuration
Second, select the appropriate version to download on the Nodejs website.
Final installation successful check and path check
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/8E/E2/wKiom1jOdAjBBM9YAAArj3ffS7Q442.jpg "title=" 36020170315204858576.jpg "alt=" Wkiom1jodajbbm9yaaarj3ffs7q442.jpg "/>
Linux, Mac system does not do the detailed
Third, Hello World
Developing web Apps with Nodejs is easy, even without having to configure a bunch of files to start the Web server
Find an example code from the official website to do Hello world!
Simple code Interpretation:
A Web server is created and only one anonymous callback function is passed in
The code has not been blocked there since the server was created successfully
It goes down to execution.
This is the event-driven programming style that will be used in a lot of this way in Nodejs
Const HTTP = require (' http '); const hostname = ' 127.0.0.1 '; const PORT = 3000;const Server = Http.createserver ((req, res) =& Gt {res.statuscode = 200; Res.setheader (' Content-type ', ' text/plain '); Res.end (' Hello world\n ');}); Server.listen (port, hostname, () = {Console.log (' server running in http://${hostname}:${port}/');});
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/8E/E2/wKiom1jOdl6RtasFAADjvbfn6u0816.jpg "title=" 36020170315204858576.jpg "alt=" Wkiom1jodl6rtasfaadjvbfn6u0816.jpg "/>
Then start the node service as follows:
Go to directory CD E:\\CODE\\JQUERY\\NODEJS\\JS start service node Server.js
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/8E/E0/wKioL1jOduay915iAAA6E8gZQS0695.jpg "title=" 36020170315204858576.jpg "alt=" Wkiol1joduay915iaaa6e8gzqs0695.jpg "/>
Then run: http://127.0.0.1:3000/
will appear in our Hello world!
Code interpretation:
Require (' HTTP ') is written by the JavaScript module, but its responsibility is to create a Web server and handle HTTP-related tasks, etc.
By Createserver to create a Web server, and then through listen to let the server listen to the request on Port 3000, you can receive any request request from that port come in to tell it what to do, so has an anonymous callback function
When is it called? When listening to Port 3000 has the content come in. There are 2 parameters, the request body req, the response body Res
git bash common commands
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/8E/E3/wKiom1jOeerQdUadAADpL4P-kEE280.jpg "title=" 36020170315204858576.jpg "alt=" Wkiom1joeerqduadaadpl4p-kee280.jpg "/>
Nodejs is essentially a JavaScript execution environment just because its encapsulation plus the web underlying processing gives it more power
What exactly is the execution environment?
Experience the JS environment in the browser, this time choose Chrome
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/8E/E1/wKioL1jOe3eiPSkoAABnwz52R6k086.jpg "title=" 36020170315204858576.jpg "alt=" Wkiol1joe3eipskoaabnwz52r6k086.jpg "/>
And in the node environment, you can write the same thing.
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/8E/E3/wKiom1jOe5iBJKjTAAApcb4BWkA496.jpg "title=" 36020170315204858576.jpg "alt=" Wkiom1joe5ibjkjtaaapcb4bwka496.jpg "/>
It can be found that there is no difference between methods and variables for normal JavaScript execution.
But the top level of their environment, the global variable, has its own special place.
Javascript:window, document
Nodejs:process
This is the difference between the execution environment of the two
This article is from the "It Rookie" blog, make sure to keep this source http://mazongfei.blog.51cto.com/3174958/1908201
node. JS (i)--nodejs Foundation