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 的默认欢迎页面。

猜你喜欢

转载自www.cnblogs.com/music-liang/p/12687593.html