Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between NodeJS http and https module?

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);
like image 862
Kamal Hussain Avatar asked Apr 15 '16 11:04

Kamal Hussain


People also ask

What is HTTPS module in Nodejs?

The HTTPS module provides a way of making Node. js transfer data over HTTP TLS/SSL protocol, which is the secure HTTP protocol.

What is difference between HTTP and express in node JS?

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.

What is the use of HTTP module?

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.

Is HTTPS built into node?

The built-in HTTPS module in Node. js helps in transferring data securely via the HTTP TLS/SSL protocol.


2 Answers

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

like image 179
Relu Mesaros Avatar answered Oct 13 '22 01:10

Relu Mesaros


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);
});
like image 23
danilodeveloper Avatar answered Oct 12 '22 23:10

danilodeveloper