Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.0 kB
2
Indexable
Never
const express = require('express');
const expressApp = require('./app.js');
const path = require('path');
const fs = require('fs');
// const { PORT } = require('./config');
// const expressApp = require('./express-app');
// dotenv.config();

const PORT = process.env.PORT || 6000;

const StartServer = async () => {
    const app = express();

    await expressApp(app);

    app.get('/', async (req, res) => {
        const filePath = path.join(__dirname, 'index.html');

        // Read the content of index.html
        fs.readFile(filePath, 'utf8', (err, html) => {
            if (err) {
                console.error('Error reading HTML file: ', err);
                return res.status(500).send('Internal Server Error');
            }
            res.send(html);
        });
    });


    app.listen(PORT, () => {
        console.log(`listening to port ${PORT}`);
    }).on('error', err => {
        console.error('Error: ', err);
        process.exit(1);
    });
};

StartServer();