Categories
JavaScript Answers

How to kill the pm2 –no-daemon process with Node?

To kill the pm2 –no-daemon process with Node, we run pm2 killorkill`.

For instance, we run

pm2 kill

to kill all pm2 processes.

Or we run

ps aux | grep PM2

to get the process ID of the pm2 process.

And we run

kill -9 [pid]

to send the KILL signal to the process with ID [pid] that we got from ps aux | grep PM2.

Categories
JavaScript Answers

How to add sub collection to a document in Firestore with JavaScript?

To add sub collection to a document in Firestore with JavaScript, we call add or set.

For instance, we write

db.collection("users").doc(username).collection("booksList").doc(myBookId).set({
  password,
  name,
  rollno,
});

to call set to update the entry in the 'booksList' collection with ID myBookId with the object we used as the argument for set.

And we write

db.collection("users").doc(username).collection("booksList").add({
  password,
  name,
  rollno,
});

to call add to add the entry we call add with to the 'booksList' collection.

Categories
JavaScript Answers

How to execute an exe file using Node?

To execute an exe file using Node, we use the execfile method.

For instance, we write

const exec = require("child_process").execFile;

exec("hello.exe", (err, data) => {
  console.log(err);
  console.log(data.toString());
});

to call exec run to hello.exe.

We get the output from data and errors from err in the callback.

Categories
JavaScript Answers

How to fix proxy not working for React and Node?

To fix proxy not working for React and Node, we need to clear cache.

To do this, we

  1. Delete package-lock.json and node_modules in the React project

  2. Turn off React terminal and npm install all dependencies again on the React project

  3. Turn back on React App

Categories
JavaScript Answers

How to glob for pattern excluding multiple files with Node.js?

To glob for pattern excluding multiple files with Node.js, we set the ignore property.

For instance, we write

const glob = require("glob");

glob(
  "**/*",
  { ignore: ["index.html", "js", "js/app.js", "js/lib.js"] },
  (err, files) => {
    console.log(files);
  }
);

to call glob with an object with the ignore property to ignore the patterns listed in the array.

And then we get the results from files.