nodejs express在监视静态资源更改后重新启动服务

wrrgggsh  于 2021-10-10  发布在  Java
关注(0)|答案(1)|浏览(342)

我用express设置了一些静态资源

import * as express from "express";
const app = express();
const port = 3000;

app.use(express.static("./static"));

app.listen(port, () => {
  console.log(`listening at http://localhost:${port}`);
});

静态目录中有一个index.html文件。我想在更改index.html后重新启动express并刷新浏览器
我试过nodemon但不是我想要的

kqlmhetl

kqlmhetl1#

安装 livereloadconnect-livereload ```
import * as express from "express";
import * as livereload from "livereload";
import * as connectLivereload from "connect-livereload";

const app = express();
const port = 3000;
const staticpath = "./static";

const liveReloadServer = livereload.createServer();
liveReloadServer.watch(staticpath);

app.use(connectLivereload());
app.use(express.static(staticpath));

app.listen(port, () => {
console.log(listening at http://localhost:${port});
});

相关问题