How to run fcc-express-bground with https

I am working through the Back End Development and APIs course and I have encountered a problem. The “solution link” box where you enter the URL of your code running only accepts an https URL but the example server.js file in the “boilerplate” github repo runs an HTTP server.

I managed to fixup the file to use https.createServer() to make it use HTTPS in the first project and I could verify my answers but the second project uses a custom package called fcc-express-bground and I can’t figure out how you are supposed to get this to use HTTPS.

As such, I can’t see how to run my code in a way that FreeCodeCamp likes so I can move on to the next section.

OK, so I figured it out.

If you edit the server.js file so that it resembles the below code then it should work ok with the freeCodeCamp verification process on the back-end development course. Obviously, you need to fill in the lines to your SSL cert and key with the relevant paths on your local machine.

Whatever you do, don’t change the port. There seems to be some code in one of the libraries that assumes that if you are running on SSL then it must be on the standard port 443. If you try to run it on any other port it falls over when the validation process runs.

var https = require('https');
var fs = require('fs'); 
var bGround = require('fcc-express-bground');
var myApp = require('./myApp');
var express = require('express');
var app = express();

if (!process.env.DISABLE_XORIGIN) {
  app.use(function(req, res, next) {
    var allowedOrigins = ['', ''];
    var origin = req.headers.origin || '*';
    if(!process.env.XORIG_RESTRICT || allowedOrigins.indexOf(origin) > -1){
         res.setHeader('Access-Control-Allow-Origin', origin);
         res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");

const options = {
  key: fs.readFileSync('path to your SSL private key'),
  cert: fs.readFileSync('path to your SSL cert')

bGround.setupBackgroundApp(app, myApp, __dirname);
const PORT = 443;
const listener = https.createServer(options, app).listen(PORT, console.log(`Node.js listening on port  ${PORT}`))

What puzzles me is how anybody has completed this course because I can’t figure out how else you can get your work validated.

It would help if you posted what challenge you are working on and your code.

Why do you believe you need https?

Sorry if it wasn’t clear but it applies to them all.

The problem was unrelated to my code, my code worked, it’s just that the verification system won’t connect to an HTTP URL and the “boilerplate” code that you have to download from here, here etc. sets up an HTTP server.

It won’t let you enter an HTTP URL for verification.

As you can see in my previous post, I fixed the supplied boilerplate code so that it works over HTTPS so my problem is solved. I am just a little confused about how other people have managed to complete this course on their local machines without modifying the supplied boilerplate code because it is incompatible with the verification system as supplied.