How to set value for NODE_TLS_REJECT_UNAUTHORIZED

nodejs

To set the value of the NODE_TLS_REJECT_UNAUTHORIZED environment variable to ‘0’, you can use one of the following methods:

  1. On the command line: You can set the value of the environment variable when starting your Node.js program using the following syntax:
NODE_TLS_REJECT_UNAUTHORIZED=0 node your-program.js
  1. In a configuration file: You can create a configuration file (e.g. .env) that sets the value of the environment variable, and then use a tool like dotenv to load the configuration file when starting your Node.js program. For example:
// .env file
NODE_TLS_REJECT_UNAUTHORIZED=0

// In your program
require('dotenv').config()
  1. In the operating system: You can set the value of the environment variable permanently in the operating system’s environment variable configuration. The specific steps to do this will depend on the operating system you are using.

Keep in mind that setting the value of NODE_TLS_REJECT_UNAUTHORIZED to ‘0’ disables certificate verification for TLS connections and HTTPS requests, which can make them insecure. It is generally not recommended to disable certificate verification, unless you have a specific reason to do so and understand the risks involved.