Skip to content

Instantly share code, notes, and snippets.

@tbutcaru-gpsw
Last active February 3, 2023 09:46
Show Gist options
  • Select an option

  • Save tbutcaru-gpsw/b000576491a34c18a4743aceff28ce21 to your computer and use it in GitHub Desktop.

Select an option

Save tbutcaru-gpsw/b000576491a34c18a4743aceff28ce21 to your computer and use it in GitHub Desktop.
const { createServer } = require("http")
const { parse } = require("url")
const next = require("next")
const dev = process.env.NODE_ENV !== "production"
const app = next({ dev })
const port = 4000
const handle = app.getRequestHandler()
const startServer = async function startServer() {
return app.prepare().then(() => {
createServer((req, res) => {
const parsedUrl = parse(req.url, true)
handle(req, res, parsedUrl)
}).listen(port, (err) => {
if (err) throw err
console.log(`> Ready on http://localhost:${port}`)
})
})
};
startServer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment