0
0
Expressframework~10 mins

HTTPS and SSL certificates in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the HTTPS module in Node.js.

Express
const https = require('[1]');
Drag options to blanks, or click blank then click option'
Aexpress
Bhttps
Chttp
Dfs
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'http' instead of 'https'
Using 'express' which is a framework, not the HTTPS module
2fill in blank
medium

Complete the code to read the SSL private key file using the fs module.

Express
const privateKey = fs.readFileSync('[1]', 'utf8');
Drag options to blanks, or click blank then click option'
Apackage.json
Bserver.cert
Cindex.js
Dserver.key
Attempts:
3 left
💡 Hint
Common Mistakes
Using the certificate file instead of the key file
Using unrelated files like 'index.js'
3fill in blank
hard

Fix the error in creating the HTTPS server with Express and SSL options.

Express
const server = https.createServer({ [1] }, app);
Drag options to blanks, or click blank then click option'
Akey: privateKey, cert: certificate
BprivateKey, certificate
Ckey = privateKey, cert = certificate
Doptions
Attempts:
3 left
💡 Hint
Common Mistakes
Passing variables without keys
Using assignment inside object literal incorrectly
4fill in blank
hard

Fill both blanks to create SSL options object with private key and certificate.

Express
const sslOptions = { [1]: privateKey, [2]: certificate };
Drag options to blanks, or click blank then click option'
Akey
Bcert
CprivateKey
Dcertificate
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names as keys
Swapping 'key' and 'cert'
5fill in blank
hard

Fill both blanks to start the HTTPS server listening on port 443 with a callback.

Express
server.listen([1], () => { console.log('Server running on port [2]'); });
Drag options to blanks, or click blank then click option'
A3000
B443
C'443'
D8080
Attempts:
3 left
💡 Hint
Common Mistakes
Using port 3000 or 8080 which are for HTTP
Passing port as a string