I am using http module in my project but most of my 'post' requests are blocked by postman. I read it is a ssl issue,after some research i found another module named https.
Here is my current code.
var http = require('http');
var server = http.createServer(app);
The HTTPS module provides a way of making Node. js transfer data over HTTP TLS/SSL protocol, which is the secure HTTP protocol.
HTTP is an independent module. Express is made on top of the HTTP module. HTTP module provides various tools (functions) to do things for networking like making a server, client, etc. Express along with what HTTP does provide many more functions in order to make development easy.
HTTP is a Node. js module which can be used to create HTTP server and client applications in JavaScript. Popular JavaScript frameworks including Express and HapiJS are built on top of the HTTP module.
The built-in HTTPS module in Node. js helps in transferring data securely via the HTTP TLS/SSL protocol.
Hei, make sure that the interceptor in Postman is off (it should be in the top, left to the "Sign in" button)
And related to https, as stated in Node.js v5.10.1 Documentation
HTTPS is the HTTP protocol over TLS/SSL. In Node.js this is implemented as a separate module.
I used it once to make requests from my server to other servers over https (port 443).
btw, your code shouldn't work, try this
const http = require('http');
http.createServer( (request, response) => {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8124);
console.log('Server running at http://127.0.0.1:8124/');
and use http://127.0.0.1:8124 in Postman ..hoped it helped
The difference between HTTP
and HTTPS
is if you need to communicate with the servers over SSL
, encrypting the communication using a certificate, you should use HTTPS
, otherwise you should use HTTP
, for example:
With HTTPS
you can do something like that:
var https = require('https');
var options = {
key : fs.readFileSync(path.resolve(__dirname, '..', 'ssl', 'prd', 'cert.key')).toString(),
cert : fs.readFileSync(path.resolve(__dirname, '..', 'ssl', 'prd', 'cert.crt')).toString(),
};
var server = https.createServer(options, app);
server = server.listen(443, function() {
console.log("Listening " + server.address().port);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With