One, Node.js introduction
These online a lot of information I'm only streamlining
1, what is Node.js
At the core: Node.js is an event-driven server-side JavaScript environment, which means we can use JavaScript to create server-side applications like the Php,ruby and Python languages. It is particularly focused on networking and creating software that interacts with the network.
2, what can you do with node.js?
It can either create a small script that operates on the file system or create a large-scale Web application to run the entire business. Thanks to Node.js's unique design, he is well suited for multiplayer games, real-time systems, networking software and applications with thousands of concurrent users.
3, install and create the first Node.js program,
Installation is very simple, you can Baidu, verify the success of Node.js installation,
can open terminal input node
Output >
Continue typing 1+1
Output 2
The installation was successful. Under the installed directory, create a new Server.js file with the following code:
JS Code
var http = require (' http ');
Http.createserver (function (req,res) {
res.writehead (200,{' content-type ': ' Text/html;charset=utf-8 '});
Res.end (' I'm writing a program \ n ' node.js ');
} Listen (4000, "127.0.0.1");
Console.log (' Server running at Http://127.0.0.1:4000/');
Then in the terminal first into the installation directory such as: Just Open is C disk, we installed in D disk
So D:
D:\>CD "program Files <x86>"
D:\Program files <x86>>cd nodejs
D:\Program files <x86> Nodejs>node server.js
Input: server running at http://127.0.0.1:4000
//termination is: Ctrl + C
We can enter url:http://127.0.0.1:4000 in the browser
The page can be displayed: I'm writing a program with Node.js.
Our first node.js was finished.