我nodemon在我的nodejs專案中使用,因為我希望每當我進行任何更改時它都會自動重新啟動一切正常但現在問題是我想使用一個包含puppeteerlib 的庫每當我進行任何更改時 nodemon 關閉 Chrome 瀏覽器并重新打開它這需要一些時間。這使我的發展緩慢。有什么辦法可以阻止這種行為。
這是我的代碼。
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每次都重新啟動。
uj5u.com熱心網友回復:
我不了解 nodemon,但是如果您可以編輯庫,則可以重新使用現有的瀏覽器。
嘗試,從節點外殼:
(await require('puppeteer').launch()).wsEndpoint()
這將回傳一個您可以重用的連接字串。
然后,您可以使用connect api連接到創建的實體
編輯:您的庫允許 ws 套接字!:-)
const client = new Client({
puppeteer: {
browserWSEndpoint: `ws://localhost:3000`
}
});
uj5u.com熱心網友回復:
在您的專案目錄中創建 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"
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/368089.html
下一篇:Websocket流檢查連接
