记录、分享、学习

Koa.js

1 min

概念

中间件 middleware

app.use(async (ctx, next) => {
  
  // ctx, context, 上下文
  
  console.log(`${ctx.method} ${ctx.url} ${new Date()}`);
  
  // next, promise,下一步
  
  return await next();
  
});
  

调试

VSCode

VS Code 侧边栏的“调试”,在代码中设置断点。

Chrome

node --inspect server.js
  
  1. chrome 打开 chrome://inspect
  2. Remote Target 选择对应的页面
  3. Source - add folder to workspace,在 server.js 中添加断点

附录