1.开发环境的配置

  1. 1.node.js
  2. 2.配置cnpm
  3. npm install -g cnpm --registry=https://registry.npm.taobao.org
  4. #如果输出不是内部或者外部命令配置一下环境变量的path路径

2.配置

  1. //卸载某个依赖
  2. cnpm uninstall xxx -S
  1. cnpm i axios -S //安装了axios
  1. //index.js
  2. const url = "xxx";
  3. /* 不写路径就会自动到node_modules这个包里面找 */
  4. const axios = require("axios");
  5. axios.get(url).then(res=>{
  6. console.log(res.data)
  7. })
  1. node index.js

3.启动服务

  1. # 安装依赖
  2. cnpm i koa -S
  1. /* 1.导入koa */
  2. const koa = require("koa");
  3. /* 2.新建一个应用 */
  4. const app = new koa();
  5. app.use(async ctx=>{
  6. ctx.body = "hello world"
  7. })
  8. app.listen(8000)
  1. node index.js //启动服务

4.安装nodemon

  1. cnpm i nodemon -g //实时监听

5修改package.json文件启动服务

  1. {
  2. "scripts":{
  3. "start" : "nodemon index.js"
  4. }
  5. }