(二)Node.js入門系列——Express.js安裝

來源:互聯網
上載者:User

標籤:style   color   os   ar   java   檔案   sp   art   c   

本篇文章講express的安裝與建立express項目。

一、安裝express

執行命令 : npm install -g express;

安裝express到npm-module,在express4.0之後,還需要安裝express-generator 來完成express項目的建立,

執行命令 : npm install -g express-generator;

二、建立Express項目

然後就能夠在目標路徑下通過express命令建立項目。如需要在 D盤 的 project檔案夾下建立項目 expressDemo:

  1. 進入D盤project目錄下:

2.    執行命令:express expressDemo ;

3.    執行命令:cd expressDemo && npm install ; 該語句會進入項目的根目錄即 expressDemo目錄下並繼續執行命令npm install 安裝項目的依賴

命令執行完成之後的目錄結構:

| - D:\project

    | - expressDemo

        | - bin

        | - node_modules

            | - .bin

            | - body-parser

            | - cookie-parser

            | - debug

            | - express

            | - jade

            | - morgan

            | - serve-favicon

        | - public

            | - images

            | - javascripts

            | - stylesheets

        | - routes

            | - index.js

            | - users.js

        | - views

            | - error.jade

            | - index.jade

            | - layout.jade

        | - app.js

        | - package.json

這時,我們的位置是:D:\project\expressDemo .

執行命令:npm start;伺服器運行,在瀏覽器運行URL:localhost:3000,即可看到預設的express頁面。

三、node-modules dependence 管理

開啟項目根目錄下的package.json檔案,能夠看到所有項目依賴的node-module都在dependencies內,類似pom的dependency,在執行npm install時,會安裝項目所依賴。

四、總結

上面介紹了Express的安裝與建立項目,通過package.json來管理項目的npm-module依賴。

但是項目中還會用到其他JS庫,比如jQuery,BootStrap等該如何管理呢?

下一篇介紹通過 bower 來管理我們的javascript庫。








(二)Node.js入門系列——Express.js安裝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.