DEV Community

Deploying a Static Next.js Site to Railway

This guide shows how to host a static Next.js site on Railway, a platform for hosting web apps. To get started, you need a GitHub account, a Railway account, and Node.js installed. Create a new Next.js app by installing react, react-dom, and next as npm dependencies and adding necessary scripts to the package.json file. Create an app folder with a layout.tsx and page.tsx file, and add a root layout and home page to these files. Run the development server and view the site at http://localhost:3000. To build the Next.js app, stop the server, add a static export configuration to next.config.js, and run the build command. This will produce an out folder with the HTML/CSS/JS assets for the application. To deploy to Railway, install the Railway CLI tool, login to your Railway account, create a new project, link the out folder to the project, and deploy the app. Once deployed, you can test the site and update it by rebuilding and redeploying the app.
favicon
dev.to
dev.to
Create attached notes ...