Categories
JavaScript Answers

How to fix Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (88) error with JavaScript?

To fix Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (88) error with JavaScript, we rebuild node-sass.

For instance, we run

npm rebuild node-sass

to rebuild the node-sass package so that it runs on the computer’s current OS.

Categories
JavaScript Answers

How to display Node.js raw Buffer data as Hex string?

To display Node.js raw Buffer data as Hex string, we call the buffer toString method.

For instance, we write

const s = buff.toString("hex");

to call toString on the buff buffer to convert it to a hex string.

Categories
JavaScript Answers

How to send headers with form data using request module with Node.js?

To send headers with form data using request module with Node.js, we call the post method.

For instance, we write

const req = require("request");

req.post(
  {
    url: "someUrl",
    form: {
      username: "user",
      password: "",
      opaque: "someValue",
      logintype: "1",
    },
    headers: {
      "User-Agent":
        "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36",
      "Content-Type": "application/x-www-form-urlencoded",
    },
    method: "POST",
  },

  (e, r, body) => {
    console.log(body);
  }
);

to call post with an object with the form property set to an object with the form data key-value pairs to send them as the post request body.

We get the response from the body parameter in the callback.

Categories
JavaScript Answers

How to add timestamp to logs using Node.js library Winston?

To add timestamp to logs using Node.js library Winston, we set the transports property to an array with the Winston console object with the timestamp option set to true.

For instance, we write

const winston = require("winston");
const logger = new winston.Logger({
  transports: [new winston.transports.Console({ timestamp: true })],
});

to create the Logger with the transports property set to an array with an array of loggers.

We create a logger with the Console constructor by calling it with an object with the timestamp property set to true to add a timestamp to each log entry.

Categories
JavaScript Answers

How to fix the ‘Uncaught Error: Module did not self-register ‘ with JavaScript?

To fix the ‘Uncaught Error: Module did not self-register ‘ with JavaScript, we remove the node_modules folder and reinstall all the packages.

To do this, we run

rm -r node_modules

to delete the node_modules folder.

Then we run

npm install

to install all packages again.