Start or serve command after nextJS project build

Hi,

In my package.json I have a custom command to start my nextJS server, eg: { "start": "node -r do-something-first ./node_modules/.bin/next start" }. I’m guessing Netlify runs next start somewhere behind the scenes after the build has completed (but I can be wrong), but it doesn’t seem to run my custom script first. Could it be that Netlify detects that my project is a NextJS project and therefore runs next start to start the server and not npm run start? How would I run a custom script every time my server is started after a successful build?

@floris10hove Have you read the Netlify next.js documentation?

Netlify doesn’t have node based hosting, so doing a start or serve wouldn’t make much sense.

Thanks for the reply. Reading the documentation still doesn’t tell me how the server works behind the scenes, but maybe that’s me and my limited knowledge of the inner workings of Netlify.

But basically you say Netlify isn’t running any start or equivalent script, because it handles incoming requests + routing to the nextjs application some other way and there is no way to run a script before “starting the server” because it’s not started in that way.

That would answer my question too; I will have to find an alternative solution to my problem then.

Netlify’s hosting is based on static files served from CDN and Serverless functions (which are AWS Lambda’s).

Node.js is available during the build step of your site, but not as a long running service afterwards.

Netlify can host Next.js based apps but it’s as per the documentation that I linked to, so for more advanced functionality there is a Runtime (mentioned in the docs), which automatically creates the serverless functions.

I haven’t said there’s “no way to run a script before ‘starting the server’”.
I’m not sure what your issue is there, your phrasing of ‘start the server’ just tipped me off that you were probably doing something that ultimately won’t work on Netlify, and that reading the docs to get a better understanding may lead you to solving your other issue too.