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() ;(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 promisify(app.listen)(3000) app.listen(3000, err=>{ if(err) throw err console.log('App listening on port 3000') }) })().catch((ex) => { console.error(ex.stack) process.exit(1) })