Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

HTTPS server with node

How do you create an https server with node? I was going through the documentation, unfortunately it's not working. thanks Thomas

// curl -k https://localhost:8000/ var https = require('https'); var fs = require('fs');

var options = { key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'), cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem') };

https.createServer(options, function (req, res) { res.writeHead(200); res.end("hello world\n"); }).listen(8000);

2 Answers

how do i generate those files then?

Hey Thomas,

I guess one of the errors you're getting looks like this: Error: ENOENT: no such file or directory, open 'test/fixtures/keys/agent2-key.pem'

Right? If so, the problem is that you're passing the options object as a parameter with two files that don't exist. Those two files (here: agent2-cert.pem and agent2-key.pem) should be your SSL certificate and your SSL key which you need in order to create a HTTPS server.

I hope that helps you to find a solution!