Install nodejs and framework express and nodejsexpress in windows

Source: Internet
Author: User
Tags install node

Install nodejs and framework express and nodejsexpress in windows

The following describes how to install node. js and the Framework express in windows.

Method 1:

The node. js Express installation can be completed in four steps.

Step 1. Install

All must be installed firstExpress-generatorOtherwise, a message is displayed when you create a project.ExpressCommand not found

Npm install-g express-generator # install express-generatornpm install-g expressexpress-V # verify whether the installation is successful

Step 2: Create a project

$ Express myfirstexpress # The default template of express uses jade. If you need ejs template support, add the-e option, that is, express-e myfirstexpress $ cd myfirstexpress $ lsapp. js bin package. json public routes views # directory structure of the project

Step 3: run the project

Copy codeThe Code is as follows:
$ Npm install # Wait for a while because you need to obtain many library files
$ Npm start

Step 4: Access the first express Project

Enter http: // 127.0.0.1: 3000 in the browser

Method 2 (text description and image combination ):

Follow these steps to install Nodejs Express:

Step 1: Install the express module, cd it to the folder, use the npm install express command to install the express module, you will find that there is a node_modules directory in the folder, there will be an express module.

Step 2: Enter any folder and execute the express app command to create an app project. The structure is as follows:

E: \ nodejs \ express_demo> express app
Create: app
Create: app/package. json
Create: app/app. js
Create: app/public
Create: app/bin
Create: app/bin/www
Create: app/public/stylesheets
Create: app/public/stylesheets/style.css
Create: app/views
Create: app/views/index. jade
Create: app/views/layout. jade
Create: app/views/error. jade
Create: app/public/images
Create: app/routes
Create: app/routes/index. js
Create: app/routes/users. js
Create: app/public/javascripts
Install dependencies: (this indicates the necessary package to be installed)
$ Cd app & npm install
Run the app: (run here, use npm start)
$ DEBUG = app./bin/www

Step 3: Cd: Enter the app folder, execute the app, and run the node app command. An error is reported at this time, because many necessary modules are missing when you use the express framework for the first time.

Error:
Module. js: 340
Throw err;
^
Error: Cannot find module 'serve-favicon '// indicates that the serve-favicon module is missing.
At Function. Module. _ resolveFilename (module. js: 338: 15)
At Function. Module. _ load (module. js: 280: 25)
At Module. require (module. js: 364: 17)
At require (module. js: 380: 17)
At Object. <anonymous> (E: \ nodejs \ Node. js {€{}}%chapter_two \ express_dem
O \ app. js: 3: 15)
At Module. _ compile (module. js: 456: 26)
At Object. Module. _ extensions.. js (module. js: 474: 10)
At Module. load (module. js: 356: 32)
At Function. Module. _ load (module. js: 312: 12)
At Function. Module. runMain (module. js: 497: 10)

Step 4:At this time, install the necessary modules as prompted,

Your environment has been set up for using Node. js 0.10.26 (ia32) and npm.
C: \ Users \ Administrator> e:
E: \> cd nodejs
E: \ nodejs> npm install serve-favicon
Serve-favicon@2.2.0 node_modules \ serve-favicon
── Ms@0.7.0
── Parseurl@1.3.0
── Fresh@0.2.4
└ ── Etag@1.5.1 (crc@3.2.1)
E: \ nodejs> npm install morgan
Morgan@1.5.1 node_modules \ morgan
── Basic-auth@1.0.0
── Depd@1.0.0
├ ── Debug@2.1.1 (ms@0.6.2)
└ ── On-finished@2.2.0 (ee-first@1.1.0)
E: \ nodejs> npm install cookie-parser
Cookie-parser@1.3.3 node_modules \ cookie-parser
── Cookie-signature@1.0.5
E: \ nodejs> npm install body-parser
Body-parser@1.12.0 node_modules \ body-parser
── Content-type@1.0.1
── Raw-body@1.3.3
── Bytes@1.0.0
── Depd@1.0.0
── Qs@2.3.3
── Iconv-lite@0.4.7
├ ── On-finished@2.2.0 (ee-first@1.1.0)
├ ── Debug@2.1.1 (ms@0.6.2)
└ ── Type-is@1.6.0 (media-typer@0.3.0, mime-types@2.0.9)
E: \ nodejs>

Step 5:After all necessary modules are installed, run the npm start command in the app and project root directory. If the system still prompts an Error similar to Error: Cannot find module 'jade ', continue to install the necessary modules.


Step 6:After all the preceding operations are completed, enter http: // 127.0.0.1: 3000/in the browser. If so, the operation is successful.

 

The above is all about installing nodejs and framework express in windows. I hope you will like it.

Related Article

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.