Node.js快速創建一個Express應用的幾個步驟


Node.js 的 Express 框架學習

 

轉載和參考地址:

https://developer.mozilla.org/zh-CN/docs/Learn/Server-side/Express_Nodejs/development_environment

https://developer.mozilla.org/zh-CN/docs/Learn/Server-side/Express_Nodejs/skeleton_website

 

1.創建一個文件夾

2.在cmd命令下,進入當前文件夾

3.初始化npm 環境(否則直接下載模塊會報錯)

npm init -y

4.安裝express模塊, generator生成器

npm install express 

npm install -g express-generator

5.進入應用目錄,運行以下命令,即可創建一個名為 "helloworld" 的 Express 應用:

express helloworld

如果不指定工程名,則會默認在當前目錄下面生成express應用。下面的截圖就是這個用法。

  =======================================================================

創建了express應用之后,系統有提示:
:\006_Project__nodejs\Demo2>express --view=pug
destination is not empty, continue? [y/N] y

create : public\
create : public\javascripts\
create : public\images\
create : public\stylesheets\
create : public\stylesheets\style.css
create : routes\
create : routes\index.js
create : routes\users.js
create : views\
create : views\error.pug
create : views\index.pug
create : views\layout.pug
create : app.js
create : package.json
create : bin\
create : bin\www

install dependencies:
> npm install

run the app:
> SET DEBUG=demo2:* & npm start
最下面2行的命令很重要!!!!!
=======================================================================

6.用下列命令可為 helloworld 應用安裝所有依賴:

cd helloworld

npm install

7.然后運行這個應用(Windows 環境):

> SET DEBUG=helloworld:* & npm start

(Linux/macOS 環境):

$ DEBUG=helloworld:* npm start

8.打開瀏覽器並訪問 http://127.0.0.1:3000/ 將看到 Express 的默認歡迎頁面。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM