1. Install the Nodejs Windows package.
Official website: http://nodejs.org/
2, you can use CMD to run the Nodejs project, the command format:
Node filename. js
Node file name
3, for unfamiliar novice coder, can use Webstorm tool, provide the function of code hint.
Official website: http://www.jetbrains.com/webstorm/
Registration code:
Webstorm Registration Code
User Name:
Embrace
License Key:
===== LICENSE BEGIN =====
24718-12042010
00001h6wzklpfo3gmjj8xotpw5mqvy
ya8vwka9th!vibauks4fidikufy!! F
3 C "Rqcirbshpsldcft1xmji5h0yqs6
===== LICENSE END =====
4. Examples of Nodejs:
?
1 2 3 4 5 6 |
var http = require(
‘http‘
); http.createServer(
function (req, res) { res.writeHead(200, {
‘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/‘
);
|
5. Code Logic:
A. Global method require () is used to import modules, generally directly assigns the return value of the Require () method to a variable, which can be used directly in JavaScript code. Require ("http") is the HTTP module that loads the system presets
B. Http.createserver is the method of the module, which is to create and return a new Web server object and bind a callback to the service to process the request.
C. The Http.listen () method allows the HTTP server to listen on a specific port.
D. Console.log will not have to say more, understand firebug should know, node implementation of this method.
6. Operation Effect:
7. NPM is the management tool for node. JS's module package, with the specific installation command:
NPM Install < package name >
8,node core thought: 1. Non-blocking; 2. Single thread; 3. Event-driven .