require('dotenv').config() const express = require('express') const nextjs = require('next') const {promisify} = require('util') const dev = process.env.NODE_ENV !== 'production' const next = nextjs({dev}) const nextRequestHandler = next.getRequestHandler() const app = express() app.listen = promisify(app.listen.bind(app)) ;(async ()=>{ // Allow Next.js to compile its templates console.log('Preparing Next.js templates . . .') await next.prepare() const app = express() app.use('/api', require('./api')) app.use(nextRequestHandler) await app.listen(3000) console.log('App listening on port 3000') })().catch((ex) => { console.error(ex.stack) process.exit(1) })