Node.js的学习路径
js基础语法+Node.js内置API模块(fs,path,http等)+第三方API模块(express,mysql)
查看版本号,ip
node -v
npm -v
ipconfig/all
Node.js 中的模块化
内置模块: fs,path,http
自定义模块(用户创建的每个.js文件)
第三方模块
向外共享模块作用域中的成员
module.exports
exports
npm
npm命令
npm init -y 快速创建package.json
npm i 一次性安装所有
npm uninstall 包名 卸载指定的包
npm i 包名 -D 开发依赖包
npm i 包名 -g 全局安装
解决下包速度慢的问题
查看当前的下包镜像源
npm config get registry
#设置为淘宝镜像
npm config set registry https://registry.npm.taobao.org
#检查是否设置成功
npm config get registry
nrm
#安装nrm
npm i nrm -g
#查看可用镜像列表
nrm ls
#设置你需要的镜像
nrm use taobao
express
npm i express@4.17.1
const express = require('express')
const app=express()
app.listen(80,()=>{
console.log('http://127.0.0.1')
}
express中的路由
// 挂载路由
app.get('/', (req, res) => {
res.send('hello world.')
})
app.post('/', (req, res) => {
res.send('Post Request.')
})
Express 中间件
xxx.use
跨域用cors