[Turn] Getting Started with NodeJS (1)---Detailed installation steps of nodejs

Beginning to learn NodeJS is to figure out what nodejs is, what it can do, and how to use it. .

what is nodejs?

    A scripting language needs a parser to run. JavaScript is a scripting language, and there are different parsers in different locations, such as the js language that writes html, and the browser is its parser role. For JS that needs to run independently, nodejs is a parser.

   Each parser is a runtime environment that not only allows js to define various data structures and perform various calculations, but also allows js to do something using the built-in objects and methods provided by the allowable environment. For example, the purpose of js running in the browser is to manipulate the DOM, and the browser provides built-in objects such as document. The purpose of js running in nodejs is to operate disk files or build http servers, and nodejs provides built-in objects such as fs and http accordingly.

 What can be done?

The author of NodeJS said that his purpose of creating NodeJS is to implement a high-performance web server, and he first valued the superiority of the event mechanism and the asynchronous IO model, not JS. But he needs to choose a programming language to implement his idea, this programming language can not have IO function, and needs to support the event mechanism well. JS does not have its own IO function, it is naturally used to handle DOM events in the browser, and has a large group of programmers, so it has become a natural choice.

As he wished, NodeJS became active on the server side, and a large number of Web services based on NodeJS appeared. On the other hand, NodeJS makes the front-end like an artifact, and finally can make its ability coverage jump out of the browser window, and a larger number of front-end tools are springing up.

Therefore, for the front end, although not everyone needs to use NodeJS to write a server program, it is as simple as debugging JS code snippets in command interactive mode, and as complicated as writing tools to improve work efficiency.

How to install (because it is a rookie, only step by step)

 Node.js installation and detailed steps

Node.js official installation package and source code download address: http://nodejs.org/download/

 

Installation environment: Windows7 x64

 

installation steps:

Step 1 : Double-click the downloaded installation package "node-v0.12.0-x64.msi" to display the welcome interface, as shown below:

 

 

Step 2: Click Next to display the Node.js license agreement page:

 

Step 3: Check "I accept the terms in the License Agreement" to agree to the license agreement, and click Next, the following interface will appear:

 

Step 4: The default installation path of Node.js is "C:\Program Files\nodejs\", you can modify it, here I changed it to D drive, click Next, the installation mode and module selection interface will appear:


  Step 5: Here I directly default Next to the next step, ready to install:

 

 

 

Step 6: After confirmation, click Install to start the installation:


Step 7: After half a minute, the installation is complete, click Finish to:



Step 8: Configure environment variables: By default, after Node.js is installed, the directory path of node.exe will be automatically configured in the path environment variable of the system, but maybe after the installation is complete, you will get an error when you enter node under the dos command.

Open the system environment variable and find that it has been configured, but running "set path" under dos can not see the configuration of nodejs, that is the problem of character. Restart the computer and reload it. You can also delete the automatic configuration and add it manually. For example: Open Computer Properties - Advanced System Settings - Environment Variables, and find the path variable in the list of system variables:


Step 9: Check if the installation is successful:

  Click start-run-cmd (win+R), open dos, enter "node --version" to check the Node.js version:

 

Npm installation related environment

1. First test whether npm is installed successfully. Since the new version of nodejs has integrated npm, npm was also installed before. You can also use the cmd command line to enter "npm -v" to test whether the installation is successful. As shown below

2. Installation related environment

npm install express -g

npm install jade -g

npm install mysql -g

 

By default, the above components are installed in the D:\dev\nodejs\node_modules folder, which is also the automatic search path for nodejs-related components.

2.1 Install Express

Express is a framework commonly used by nodejs 'npm install express -g' in -g means to install in the lib of NODE_PATH

Ps: After installing express, creating a new project sometimes encounters abnormal situations, prompting " express is not an internal or external command ", the reason: the command tool is separated in the express4.x version, you need to install another command tool, execute After the command " npm install -g express-generator " is completed, you can test it.

Reference the express package in the project

Create a project with express

 Enter [express project name] in the command line to create a new project in the current folder

With this method, just create an empty project framework, and a simple example program, run app.js to view (you also need to install the jade package in the project file directory, the method is similar to installing express)

Reference the express package in the project


Create a project with express

  Enter [express  project name] in the command line to create a new project in the current folder


With this method, just create an empty project framework, and a simple example program, run app.js to view (you also need to install the jade package in the project file directory, the method is similar to installing express)


With this method, just create an empty project framework, and a simple example program, run app.js to view (you also need to install the jade package in the project file directory, the method is similar to installing express )

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325733119&siteId=291194637