--- title: '使用deno开发post请求,get请求,监测文件变化自动重启(类似于nodemon)' date: 2021-09-09 15:59:00 --- ![](https://img-blog.csdnimg.cn/2021090915551595.png) launch.js: ```javascript const run = () => { return Deno.run({ cmd: ['deno', 'run', '--allow-net', '--allow-read', 'index.js'], cwd: 'app', }) } let myPorcess = run() const watcher = Deno.watchFs('./app') for await (const event of watcher) { console.log(event) console.log('kill proceess') myPorcess.close() console.log('restart') myPorcess = run() } ``` app/index.js: ```javascript import { Application, Router, helpers } from 'https://deno.land/x/oak/mod.ts' const app = new Application() const router = new Router() router.get('/list', async (ctx) => { const { id } = helpers.getQuery(ctx, { mergeParams: true }) ctx.response.body = { state: 1, data: { id }, message: '成功', } }) router.post('/login', async (ctx) => { const result = ctx.request.body() console.log(66678910) if (result.type === 'json') { const { username } = await result.value ctx.response.body = { state: 1, data: { username }, message: '成功', } } }) app.use(router.routes()) app.use(router.allowedMethods()) app.listen({ port: 8000 }) console.log(8000) ``` 启动命令: ```javascript deno run --allow-net --allow-read --allow-run launch.js ``` 自动重启: ![](https://img-blog.csdnimg.cn/20210909155845794.png?x-oss-processimage/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5b6Q5ZCM5L-d,size_20,color_FFFFFF,t_70,g_se,x_16) post请求: ![](https://img-blog.csdnimg.cn/20210909155645724.png?x-oss-processimage/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5b6Q5ZCM5L-d,size_20,color_FFFFFF,t_70,g_se,x_16) get请求: ![](https://img-blog.csdnimg.cn/20210909155710748.png?x-oss-processimage/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5b6Q5ZCM5L-d,size_20,color_FFFFFF,t_70,g_se,x_16) 参考链接: [https://zhuanlan.zhihu.com/p/143947500](https://zhuanlan.zhihu.com/p/143947500) [https://deno-tutorial.js.org/articles/index.html](https://deno-tutorial.js.org/articles/index.html)