express-generator
npm i express-generator -g 安装express脚手架
express <项目名称> [options] 安装express脚手架
eg:express my-app
常用的包已经node运行命令的配置
以下的配置有
用于兼容es6的包 cross babel-cli
热更新 nodemon
链接mongodb 以及 操作 mongodb实体的包
express-session 是 操作session
链接redis(connect-redis)操作 ioredis
time-formater时间格式化
formidable 用于处理表单提交 表单要有这个属性 enctype=“multipart/form-data” 因为有这个属性之后就自动设置特殊的请求头
gm是用于对图像进行处理的插件 (我不会用)
还有其他常用
比如 mysql
插件用于连接数据co-mysql
使操作mysql数据更加方便 一会在下面写栗子
{
"name": "myhoutai",
"version": "0.0.0",
"main": "index.js",
"private": true,
"listen": "GPL",
"scripts": {
"dev": "cross-env NODE-ENV=development nodemon --harmony index.js --exec babel-node"
},
"dependencies": {
"babel-cli": "^6.26.0",
"body-parser": "^1.19.0",
"connect-mongo": "^3.2.0",
"connect-redis": "^4.0.3",
"cookie-parser": "~1.4.4",
"cross": "^1.0.0",
"cross-env": "^6.0.3",
"crypto": "^1.0.1",
"debug": "~2.6.9",
"express": "^4.16.4",
"express-session": "^1.17.0",
"formidable": "^1.2.1",
"gm": "^1.23.1",
"http-errors": "~1.6.3",
"ioredis": "^4.14.1",
"jade": "~1.11.0",
"mongodb": "^3.3.5",
"mongoose": "^5.8.0",
"morgan": "~1.9.1",
"nodemon": "^2.0.1",
"time-formater": "^1.1.3"
},
"devDependencies": {
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-2": "^6.24.1"
}
}
使用cnpm install
安装包
之后
cnpm i babel-core babel-loader@7.x babel-plugin-transform-runtime -D // 将高级语法转化为低级语法
cnpm i babel-preset-env babel-preset-stage- -D // 规定语法规定
.babelrc 用于兼容es6创建然后放到根目录下
{
"presets": ["es2015", "stage-2"],
"plugins": []
}
co-mysql
import goods from '../linkDB'
import wrapper from 'co-mysql'
let conn = wrapper(goods);
let res = await conn.query('insert into goods set ? ',data);
奥吼吼~~
发布了93 篇原创文章 · 获赞 19 · 访问量 5333
私信
关注