防止 Nodemon 重启某些特定代码
Prevent Nodemon to restart some specific code
我在我的 nodejs
项目中使用 nodemon
因为我希望每当我进行任何更改时它都会自动重新启动一切正常但现在问题是我想使用一个库
每当我进行任何更改时,其中包括 puppeteer
lib nodemon 关闭铬浏览器并重新打开它需要一些时间。这让我的发展变慢了。有什么办法可以阻止这种行为。
这是我的代码。
const express = require("express");
const app = express();
const http = require("http");
const server = http.createServer(app);
const { Client } = require("whatsapp-web.js");
const client = new Client({ puppeteer: { headless: false } });
client.initialize();
console.log("changes 7");
server.listen(3000, () => {
console.log("listening on *:3000");
});
每当我进行任何更改时,它都会重新启动所有内容。我不想每次都重新启动 client
。
我不知道 nodemon,但如果你可以编辑库,你可以重新使用现有的浏览器。
尝试,从节点shell:
(await require('puppeteer').launch()).wsEndpoint()
此 return 一个可以重复使用的连接字符串。
然后,您可以使用 connect api
连接创建的实例
编辑:您的库允许 ws 套接字! :-)
const client = new Client({
puppeteer: {
browserWSEndpoint: `ws://localhost:3000`
}
});
在您的项目目录中创建 nodemon.json
nodemon 将自动查找此文件并在存在时使用它
并写入 nodemon.json
{
//list of directory you want to watch
"watch": ["./","server","someOtherDir"],
"ext": "js,ts,json", //file extension to watch
"ignore": ["ignoreThisDir","someDir/*.js"], //specify files or directory to ignore
// specify entry of the project
"exec" : "node app.js"
//another example for exec "exec": "ts-node --project tsconfig.server.json server/app.ts"
}
我在我的 nodejs
项目中使用 nodemon
因为我希望每当我进行任何更改时它都会自动重新启动一切正常但现在问题是我想使用一个库
每当我进行任何更改时,其中包括 puppeteer
lib nodemon 关闭铬浏览器并重新打开它需要一些时间。这让我的发展变慢了。有什么办法可以阻止这种行为。
这是我的代码。
const express = require("express");
const app = express();
const http = require("http");
const server = http.createServer(app);
const { Client } = require("whatsapp-web.js");
const client = new Client({ puppeteer: { headless: false } });
client.initialize();
console.log("changes 7");
server.listen(3000, () => {
console.log("listening on *:3000");
});
每当我进行任何更改时,它都会重新启动所有内容。我不想每次都重新启动 client
。
我不知道 nodemon,但如果你可以编辑库,你可以重新使用现有的浏览器。
尝试,从节点shell:
(await require('puppeteer').launch()).wsEndpoint()
此 return 一个可以重复使用的连接字符串。
然后,您可以使用 connect api
连接创建的实例编辑:您的库允许 ws 套接字! :-)
const client = new Client({
puppeteer: {
browserWSEndpoint: `ws://localhost:3000`
}
});
在您的项目目录中创建 nodemon.json
nodemon 将自动查找此文件并在存在时使用它
并写入 nodemon.json
{
//list of directory you want to watch
"watch": ["./","server","someOtherDir"],
"ext": "js,ts,json", //file extension to watch
"ignore": ["ignoreThisDir","someDir/*.js"], //specify files or directory to ignore
// specify entry of the project
"exec" : "node app.js"
//another example for exec "exec": "ts-node --project tsconfig.server.json server/app.ts"
}