Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting HTTPS in Express 4.x

I'm trying to start the server in HTTPS using Express 4.x. I tried

  var credentials = {key: privateKey, cert: certificate};
  var app = express(credentials);

But it's not working.

like image 224
user203617 Avatar asked May 07 '14 19:05

user203617


People also ask

How do I run node js in https?

To start your https server, run node app. js (here, app. js is name of the file) on the terminal. or in your browser, by going to https://localhost:8000 .

Does Express need HTTP?

There's really no reason to create your own http server using the http module. Express will just do that for you with app. listen() just fine and save you little bit of typing. If you were creating an https server, then you would need to use the https module and pass security credentials to https.


1 Answers

You could easily just do something like this:

var app = express(),
    credentials = {key: privateKey, cert: certificate},
    server = https.createServer(credentials, app);
server.listen(8443);
like image 200
mscdex Avatar answered Oct 09 '22 12:10

mscdex