I am facing a problem with client side https requests.
A snippet can look like this:
var fs = require('fs');
var https = require('https');
var options = {
hostname: 'someHostName.com',
port: 443,
path: '/path',
method: 'GET',
key: fs.readFileSync('key.key'),
cert: fs.readFileSync('certificate.crt')
}
var requestGet = https.request(options, function(res){
console.log('resObj', res);
}
What I get is Error: self signed certificate in certificate chain.
When I use Postman I can import the client certificate and key and use it without any problem. Is there any solution available?? I would also like to be given some lights on how postman handles the certificates and works.
Kenil Vasani
From your question I’m guessing you are doing this in development as you are using a self signed certificate for SSL communication.
If that’s the case, add
NODE_TLS_REJECT_UNAUTHORIZED='0'
as an environment variable wherever you are running node or running node directly withNODE_TLS_REJECT_UNAUTHORIZED='0' node app.js
This instructs Node to allow untrusted certificates (untrusted = not verified by a certificate authority)
If you don’t want to set an environment variable or need to do this for multiple applications npm has a configuration you can set using the command
npm config set strict-ssl=false
I would not recommend setting this environment variable in production. Use a free SSL cert from a trusted provider like letsencrypt.org