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:
xxxxxxxxxx
1
NODE_TLS_REJECT_UNAUTHORIZED=0 node ./index.js
e.g. Windows Command Prompt (cmd.exe):
xxxxxxxxxx
1
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()
:
xxxxxxxxxx
1
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:
xxxxxxxxxx
1
const request = https.request({
2
host: 'example-host.com',
3
port: 443,
4
path: '/',
5
method: 'GET',
6
rejectUnauthorized: false
7
};
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 commentsShow commentsAdd comment