Deployment: npm start issues
roygatling
HOBBYOP

a month ago

I have a web app that has a frontend and server. I use npm run server and npm run dev to start these locally.

I updated my deployment settings with npm run server && npm run dev. I get an error and here is the log output.

Any thoughts on what I'm doing wrong?

Starting Container

npm warn config production Use --omit=dev instead.

npm warn config production Use --omit=dev instead.

> construction-spec-analyzer@1.0.0 dev

> vite

> construction-spec-analyzer@1.0.0 server

> node server.js

VITE v5.4.8 ready in 311 ms

Local: http://localhost:5173/

Network: use --host to expose

[dotenv@17.2.3] injecting env (0) from .env -- tip: load multiple .env files with { path: ['.env.local', '.env'] }

Server running on port 3001

Database connected successfully

Stopping Container

Solved$10 Bounty

2 Replies

Railway
BOT

a month ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


sarahkb125
EMPLOYEE

a month ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open sarahkb125 about 2 months ago


sumon9836

1. Problem:Currently, the start command is npm run server && npm run dev. This doesn’t work because the backend (server.js) keeps running and blocks the frontend (vite dev server) from starting. Railway can only run one process at a time in a container.2. Solution Overview:Build the frontend first.Serve the built frontend using the backend.Start only the backend on Railway.3. Step 1: Update package.jsonUpdate the scripts section:"scripts": {"dev": "vite","server": "node server.js","build": "vite build","start": "node server.js"}4. Step 2: Update server.js to serve frontendAdd the following to your backend:import express from "express";import path from "path";import { fileURLToPath } from "url";const __dirname = path.dirname(fileURLToPath(import.meta.url));const app = express();// Serve frontend buildapp.use(express.static(path.join(__dirname, "dist")));app.get("*", (_, res) => {res.sendFile(path.join(__dirname, "dist", "index.html"));});const PORT = process.env.PORT || 3001;app.listen(PORT, () => console.log(`Server running on port ${PORT}`));5. Step 3: Railway SettingsBuild command: npm run buildStart command: npm startMake sure the server listens on process.env.PORT6. Step 4: DeployRun build locally or on Railway.Deploy using the updated start command.The backend will serve the frontend and handle API requests.7. Result:Frontend is built and served from the backend.Railway runs a single process (server.js) and the app works correctly.

roygatling
HOBBYOP

a month ago

Thank you for your help! It took me a bit a back and forth, but it's working now.


Status changed to Solved uxuz about 2 months ago


Loading...