Kamal Hussain
Kamal Hussain

Reputation: 305

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);

Upvotes: 10

Views: 12141

Answers (4)

Joker38
Joker38

Reputation: 5

Hyper-text exchanged using HTTP goes as plain text
i.e. anyone between the browser and server can read it relatively easily if one intercepts this exchange of data due to which it is Insecure.

HTTPS is considered to be secure but at the cost of processing time.
This is because Web Server and Web Browser need to exchange encryption keys using Certificates before actual data can be transferred.

HTTP works on Application layer.
HTTPS works on Transport layer.
This makes HTTPS more secure, encrypted but little bit slower than HTTP.

Upvotes: -1

danilodeveloper
danilodeveloper

Reputation: 3880

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);
});

Upvotes: 2

Rajesh Reddy
Rajesh Reddy

Reputation: 39

const http = require('http');
http.createServer( function(request, response) {
   response.writeHead(200, {'Content-Type': 'text/plain'});
   response.end('Hello World\n');
}).listen(3000);
console.log('Server running at http://localhost:3000/');

Upvotes: 1

Relu Mesaros
Relu Mesaros

Reputation: 5038

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

Upvotes: 4

Related Questions