How to generate and use a SSL certificate in NodeJS

Mafia Codes · 118K views · 2020 · 13:59

Open on YouTube

Web developmentSecurity & hackingtutorial

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about getting a Node.js or Express server to serve HTTPS with an SSL certificate.

Recommended by 0 people across 0 different months, 2021 to 2021.

What it is

A roughly 14-minute tutorial from the Mafia Codes channel on generating self-signed SSL/TLS certificates with OpenSSL for development. It then shows how to use them to run an HTTPS server in a Node.js Express app.

What people said

Cites Tushant Rajpal · 2021-04 · Stack Overflow · on “Bad Request - Invalid URL HTTP Error 400. The request URL is invalid. while using SSL on domain name and JWT token inside NodeJS”

I have found the answer to my own question. It is the issue of SSL not linked with my nodejs application. So in this situation, I have used the SSL configuration while creating the HTTPS server and it has solved my issue. This is the link to the answer [this video]

Cites white lotus · 2021-05 · Stack Overflow · on “I want to render a node.js page with headers served by http2”

Found solution here: [ [this video] ][1] const express = require('express') const https = require('https') const path = require('path') const fs = require('fs') const app = express() app.use('/', (req, res, next) => { res.send('Hello from SSL server') }) // app.listen(3000, () => {}) const sslServer = https.createServer({ key: fs.readFileSync(path.join(__dirname, 'cert', 'key.pem')), cert: fs.readFileSync(path.join(__dirname, 'cert', 'cert.pem')) }, app) sslServer.listen(3443, () => console.log('Secure Server on port 3443')) // SELF-SIGNED CERTIFICATE // openssl genrsa -out key.pem // openssl req -new -key key.pem -out csr.pem // openssl x509 -req -days 365 -in csr.pem -signkey key.pem -out cert.

Cites Julie · 2021-10 · Stack Overflow · on “How can I run node and apache on the same server to allow the user to access api through https?”

The answer is to secure the node backend server in order for the user to stay on the secure HTTPS address. You do this by assigning SSL keys to the node server. Then edit the app.js file to connect to HTTPS , not HTTP . The above app.js connects to HTTP only. So this needed to be fixed. Finally, edit your reverse proxies in the Apache virtual hosts to fwd HTTP to HTTPS . In my case, the frontend was secure via HTTPS SSL certificates from let's encrypt ( certbot ) ie [LINK] , but the backend was not secure, so when I tried to go to [LINK] there was an error. The reason for this was because the backend app.js file connected to an HTTP server when it needed to connect to HTTPS . Note : if you h