node.js下面创建一个express应用的几条命令【乱序版】

https://github.com/mdn/express-locallibrary-tutorial

https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/Introduction

(用chrome浏览器打开,然后记得用google的自动翻译功能,将页面的内容都自动翻译为中文)

地2个连接是个非常不错的入门文章。非常全面和详细。下面的命令,都是这篇文章里面用到的,特意整理的。

这个文章还有一个完整的 图书馆 工程。

https://www.expressjs.com.cn/starter/installing.html


1.创建一个文件夹

2.在cmd命令下,进入当前文件夹

3.初始化npm 环境(否则直接下载模块会报错)
npm init -y

4.安装express模块, generator生成器
npm i -S express express-ws -g
npm install -g express-generator
npm install mongodb
npm install mongoose

5.进入应用目录,运行以下命令,即可创建一个名为 "helloworld" 的 Express 应用:
express helloworld --view=pug


=======================================================================
创建了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

==================================
安装了express的应用之后,需要执行 npm install。。。
在 express 应用的同级目录下指向该命令。
==================================


7.然后运行这个应用(Windows 环境):
> SET DEBUG=helloworld:* & npm start

(Linux/macOS 环境):
$ DEBUG=helloworld:* npm start


8.打开浏览器并访问 http://127.0.0.1:3000/ 将看到 Express 的默认欢迎页面。

=====================================================
文件改动时,重启服务器
npm install -g nodemon
npm install --save-dev nodemon

SET DEBUG=demo2:* & npm run devstart

--------------------------------------------
F:\006_Project__nodejs\Demo2>SET DEBUG=demo2:* & npm run devstart

> [email protected] devstart F:\006_Project__nodejs\Demo2
> nodemon ./bin/www

[nodemon] 2.0.3
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node ./bin/www`
demo2:server Listening on port 3000 +0ms
GET / 304 644.464 ms - -
GET /stylesheets/style.css 304 2.863 ms - -
---------------------------------------------------


express-locallibrary-tutorial-master

SET DEBUG=express-locallibrary-tutorial:* & npm start

SET DEBUG=express-locallibrary-tutorial:* & npm run devstart

SET DEBUG=Lobby:* & npm run devstart


npm install async
npm install express-validator
npm install compression
npm install helmet
npm install moment
npm install express-validator --save


npm install pug
npm install pug-cli -g

SET DEBUG=libraryExpress:* & npm run devstart

生成数据库文件
node .\populatedb.js 'mongodb://127.0.0.1/my_library'

猜你喜欢

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