I have a Next.js application that uses Better-SQLite3 as its database. I want to deploy it on cPanel. Here's what I did:
Ran
npm run buildlocally.Zipped all files except
node modules.Uploaded the zip to
public html/my-appon cPanel and extracted it.In the Node.js setup section on cPanel, I:
Selected Node version: 20.20.0
Application mode: production
Application root:
public html/my-appApplication URL:
https://example.com/myappStartup file:
server.js
Ran “NPM Install” in cPanel.
Started the application.
When I visit https://example.com/my-app, I get a 503 error: “Server is temporarily busy, try later.”
How to fix that and make it work successfully?
My server.js looks like this:
const { createServer } = require("http");
const { parse } = require("url");
const next = require("next");
const port = process.env.PORT || 3000;
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
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}`);
});
});