#standalone

1 messages · Page 1 of 1 (latest)

haughty cape
#

Hey, I am creating a standalone output to my VPS. But my standalone always serves on port 3000. How can I change this?

half violetBOT
#

Hi @haughty cape. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

When using Next.js with standalone output, you can change the default port (3000) by setting environment variables before running the server.js file. According to the documentation, you can define the PORT environment variable to specify a different port:

PORT=8080 node .next/standalone/server.js

If you also need to specify a hostname (for example, to make your app accessible from other devices on your network), you can use the HOSTNAME environment variable:

PORT=8080 HOSTNAME=0.0.0.0 node .next/standalone/server.js

This will start your server on <http://0.0.0.0:8080> instead of the default <http://localhost:3000.>

Next.js Output Configuration specifically mentions this in their documentation:

If your project needs to listen to a specific port or hostname, you can define PORT or HOSTNAME environment variables before running server.js.

This approach works for the standalone output mode where Next.js generates a minimal server.js file during the build process.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: