EN
Node.js - disable certificate validation
1
answers
3
points
How can I disable certificate validation in Node.js?
1 answer
3
points
Solution 1
Run Node.js from command line using environemnt variable.
e.g. Bash:
NODE_TLS_REJECT_UNAUTHORIZED=0 node ./index.js
e.g. Windows Command Prompt (cmd.exe):
set NODE_TLS_REJECT_UNAUTHORIZED=0&&node ./index.js
Note: you can find universal solution here.
Solution 2
Use the following line before https.request():
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
Note: it is recommended to paste it at the beginning of application.
Solution 3
Alternatively, in request options you can set rejectUnauthorized to false value:
const request = https.request({
host: 'example-host.com',
port: 443,
path: '/',
method: 'GET',
rejectUnauthorized: false
};
Warning:
Disabling certificate validation disables all kinds of security checks, don't use it in production environment. Use this solutions for testing purposes only.
References
0 comments
Add comment