Home > Mobile >  Prevent Nodemon to restart some specific code
Prevent Nodemon to restart some specific code

Time:11-28

I'm using nodemon in my nodejs project because I want whenever I made any changes it will restart automatically everything works fine but now problem is I want to use a lib which include puppeteer lib whenever I made any changes nodemon close the chromium browser and re-open it which take some time. This is making me slow in development. Is there any way I can stop this behaviour.

Here is my code.

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");
});

Whenever I made any changes it restart everything. I don't want to restart the client every time.

CodePudding user response:

I don't know about nodemon, but if you can edit the library, you can re-use an existent browser.

Try, from node shell:

(await require('puppeteer').launch()).wsEndpoint()

this return a connection string that you can reuse.

And, then, you can connect with the created instace with connect api

Edit: your library allows ws socket! :-)

const client = new Client({ 
    puppeteer: {
        browserWSEndpoint: `ws://localhost:3000`
    }
});

CodePudding user response:

create nodemon.json in your project directory nodemon will automatically look for this file and use it if exist and write in 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"

}

  • Related