MartinZeltin
4 months ago

How to separate Node.js app into 2 different files?

Posted 4 months ago by MartinZeltin

I have a simple Node.js app. But I would like to extract one part of it into another file but I don't know how to do this.

Here is my app

const fs = require('fs')
const https = require('https')
const express = require('express')

const app = express()

const server = https.createServer({
    cert: fs.readFileSync('/etc/letsencrypt/live/www.4evergaming.com/cert.pem'),
    key: fs.readFileSync('/etc/letsencrypt/live/www.4evergaming.com/privkey.pem'),
}, app)


server.listen(443)

I would like to put this part into a file certificate.js and include it in my main app.js file

certificate.js

const server = https.createServer({
    cert: fs.readFileSync('/etc/letsencrypt/live/www.4evergaming.com/cert.pem'),
    key: fs.readFileSync('/etc/letsencrypt/live/www.4evergaming.com/privkey.pem'),
}, app)

I would appreciate some help on this...

Please sign in or create an account to participate in this conversation.