Since the project needs, recently began to learn Nodejs. During the learning process, record some necessary actions and points that should be noted.
How to install the NODEJS environment first? (I'm using a Windows 7 environment, so it's mostly the Windows 7 example.) If you want to see the installation under Linux refer to http://www.cnblogs.com/meteoric_cry/archive/2013/01/04/2844481.html) 1. Nodejs provides a number of installation programs, you can go to the official website (http://nodejs.org/download/) to download according to their own machine, after the download is complete, you can install 1.1 ctrl+r input cmd to open the console, Run node-v display node version, if normal, instructions for installation success 1.2 input node into the REPL (Read-eval-print Loop) environment, an interactive environment. You can input the JS code directly after node, or you can execute the JS file and enter node Example.js. 2. Webstorm+nodejs, using any editor in principle, is recommended to use Webstorm, which integrates node's development environment (webstorm:http://www.jetbrains.com/webstorm/) 2.1 Download and install webstorm 2.2 Open Webstorm and new project 2.3 Click Settings icon to set up & nbsp 2.4 Select node. js and NPM, then click Configure to download the Nodejs source package, in the future development can be prompted and view the source code, after the download is complete, click OK to generate settings on line 2.5 Create a new helloworld.js, right-run the Helloworld.js file, and the Webstorm console displays Hello world Second understanding of some concepts in Nodejs 1. Module in Nodejs the different functions of JS placed in a file, this file is a module, the path is the module name. Each module has three pre-definedVariables: Require, exports, module 1.1 require for introducing other modules in the current module
var http = require (' http ');
1.2 Exports the export object of the current module, which is used to export the module public methods and properties. The exports object of the current module is obtained by Requrie.
Exports.hello = function () { console.log (' Hello world! '); }
1.3 Module can access some relevant information of the current module, with the most used to replace the current export module
Module.exports = function () { console.log (' Hello world! '); }
2. Packages Packages are used to implement a large feature that may be used during the period to other modules While the directory also has Package.json and readme.md Use third-party packages can be queried here: https://www.npmjs.org/, you can also upload their own packages. Again is to view the API documentation to complete the functionality you want to implement English documents:https://www.npmjs.org/doc/ Chinese documents:/HTTP nodeapi.ucdok.com/#/api/all.html finally is practice. In the subsequent learning process, will do some of the practice. Reference: http://nqdeng.github.io/7-days-nodejs/