Creating a nextjs app dir deployment for a nodejs server
Unanswered
Long-billed Curlew posted this in #help-forum
Long-billed CurlewOP
The project is a nextjs app dir based project where it has to be hosted on a nodejs server, I've built the code, but i can't wrap my head around which file i should be making the starting point
11 Replies
Long-billed CurlewOP
@Anay-208
You can also use
npm run build and npm start. But still, I'll tell what you need to doinstall next and express using
npm i express nextconst express = require('express');
const next = require('next');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
const server = express();
server.all('*', (req, res) => {
return handle(req, res);
});
const port = process.env.PORT || 3000;
server.listen(port, (err) => {
if (err) throw err;
console.log(`> Ready on http://localhost:${port}`);
});
}); app.js"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
}package.json
@Long-billed Curlew is your issue resolved
@Anay-208 <@898949804024012850> is your issue resolved
Long-billed CurlewOP
It's kindof messed,
Btw can you say if that will reduce any feature of cause jn some performance issues
Btw can you say if that will reduce any feature of cause jn some performance issues
@Long-billed Curlew It's kindof messed,
Btw can you say if that will reduce any feature of cause jn some performance issues
there might be performance issues and feature lost
@Long-billed Curlew The project is a nextjs app dir based project where it has to be hosted on a nodejs server, I've built the code, but i can't wrap my head around which file i should be making the starting point
you could push the code to the server and install the dependencies,
npm run build then npm start to spin it up. Or setup a github workflow to build a standalone output then scp the folder to the server