主题
动态加载nodejs的启动方式汇总
安装全局express命令行
bash
npm install express-generator -D生成项目,并且安装项目依赖的包
bash
express server
cd server
npm i启动方式
bash
node bin/www访问 localhost:3000
添加git忽略文件 .gitignore
.DS_Store
node_modules/
dist/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
test/unit/coverage
test/e2e/reports
selenium-debug.log
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln优化启动方式,让每次修改代码后不需要重启
使用nodemon方式:
nodemon安装:
bash
全局安装:
npm install -g nodemon
or
本地安装:
npm install --save-dev nodemon在package.json里面配置快捷启动方式
在package.json 的scripts选项里面添加
bash
"scripts": {
"start": "node ./bin/www",
"dev": "nodemon ./bin/www"
},此时启动方式是:
bash
npm run dev使用supervisor方式
使用方式说明
bash
安装
npm install supervisor -g
使用
supervisor bin/www把supervisor bin/www 的启动的方式添加到package.json
在package.json 的scripts选项里面添加
bash
"scripts": {
"start": "node ./bin/www",
"sup": "supervisor ./bin/www"
},此时启动方式是:
bash
npm run sup使用pm2的方式
详细使用方式请去官网pm2
全局安装
bash
npm install pm2 -g
启动方式
pm2 start ./bin/www在package.json 的scripts选项里面添加
bash
"scripts": {
"start": "node ./bin/www",
"pm2": "pm2 start ./bin/www"
},此时启动方式是:
bash
npm run pm2使用node-dev的方式
全局安装
bash
npm install node-dev -g在package.json 的scripts选项里面添加
bash
"scripts": {
"start": "node ./bin/www",
"dev": "node-dev ./bin/www"
}此时启动方式是:
bash
npm run pm2同时运行多个命令 (concurrently)
INFO
你可以选择全局安装
bash
npm install -g concurrentlyINFO
也可以局部安装
bash
npm install concurrently --save-devINFO
用法请记住用引号将每个单独的命令括起来,如下所示
bash
concurrent "command1 arg" "command2 arg"INFO
否则,concurrent将尝试运行4个单独的命令:
bash
command1, arg, command2, argINFO
在双引号内需要转义
bash
"concurrently \"npm run dev:preload\" \"npm run dev:electron\""