Install and configure node. js + express development environment under win7 _ node. js

Source: Internet
Author: User
The installation of nodejs and framework express in Windows 7 has been popular since its birth. I recently installed an environment to learn about it. The installation steps are simple and simple. I would like to share them with you. 1. install node. js.

Go to the official website: http://www.nodejs.org/download. Select Windows Installer or Windows Installer (. msi) 32-bit to download the installation package. After the download is complete, double-click the installation.

2. install Express.

The nmp package manager is used for installation. the installation is classified into global installation: automatically installed under "C: \ Users \ [current user] \ AppData \ Roaming \ npm, the Path is automatically added to the environment variable "Path. Local installation: installation to the current directory does not add the path to the environment variable "Paht. To facilitate use and run the "express" command in any path in the command line, the global installation is preferred. OK! Enter "npm install-g express" in the command line ". Note: "-g" is the global installation option, and local installation is not required.

3. create an Express project.

4. open package. json and edit the template engine.

"Jade": "> = 0.0.1" changed to "ejs": "> = 0.6.0"

After saving, switch to cmd and execute

Npm installl

Check the package. json in the current directory and automatically install the required extension.

Node_modules is added to the site directory, which is the extension library file.

I personally don't like express's built-in jade template engine, so I use ejs templates with the same syntax as jsp.

Node app. js

Open the browser http: // 127.0.0.1: 3000/and you will be able to access it.

Next let's take a look at creating a project

Now there is express

The express command takes effect only when it is installed globally!

Therefore, when installing express, use npm install express-g

Or directly modify the global path:

Npm config set prefix "C: \ Program Files \ nodejs"

Npm config set cache "C: \ Program Files \ nodejs \ cache" (create the cache directory first)

Type: express myapp (myapp is a random project name)

You will find an additional C: \ Program Files \ nodejs \ myapp Directory

By default

I don't want to explain these files. I believe that anyone with development experience can understand them at a glance.

Copy node_modules to myapp

After the environment is set up, we will perform a demo test!

Create helloworld. js under myapp

var http = require("http");http.createServer(function(request, response) {   response.writeHead(200, {"Content-Type": "text/plain"});   response.write("Hello World");   response.end();}).listen(8888);console.log("nodejs start listen 8888 port!");

Go to the node. js command prompt command window and enter the C: \ Program Files \ nodejs \ myapp directory.

Type node helloworld. js

Http: // 127.0.0.1: 8888/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.