Hi everyone,
I’m building a Shopify app where:
-
The frontend and authentication (including Prisma-based session handling) are built using Remix.
-
The backend APIs are built separately using Node.js, Express, and Mongoose.
-
For development:
-
I run the Remix app using npm run dev (handles Shopify app install and session).
-
I run the backend APIs using npm run server.
-
My question is:
Do I need two separate servers for deployment, or is it possible to deploy both the Remix app and the Express API on a single server?
If it’s possible to run everything on one server, what’s the best way to do that?
This is my backend server code:
import dotenv from “dotenv”;
dotenv.config();
import express from “express”;
import cors from “cors”;
import { connectDB } from “./config/db.js”;
const app = express();
const port = process.env.PORT || 8000;
console.log(“env DB URL from index.js:”, process.env.DATABASE_URL);
app.use(express.json());
app.use(express.urlencoded());
// Configure CORS properly
app.use(cors({
origin: ‘*’,
methods: [‘GET’, ‘POST’, ‘PUT’, ‘DELETE’],
allowedHeaders: [‘Content-Type’, ‘Authorization’],
}));
// MongoDB Connection
connectDB();
// Routes import
import VerficationSettingRoutes from “./routes/verification.routes.js”;
import planRoutes from ‘./routes/plan.routes.js’;
import verificationLogRoutes from “./routes/verificationLog.routes.js”;
import analyticsRoutes from “./routes/analytics.routes.js”;
import supportRoutes from “./routes/support.routes.js”;
import ocrRoutes from “./routes/upload.routes.js”;
import toggleRoutes from “./routes/toggle.routes.js”;
// Routes declaration
app.use(‘/api/v1’, VerficationSettingRoutes);
app.use(‘/api/v1’, planRoutes);
app.use(‘/api/v1’, verificationLogRoutes);
app.use(‘/api/v1’, analyticsRoutes);
app.use(‘/api/v1’, supportRoutes);
app.use(‘/api/v1’, ocrRoutes);
app.use(‘/api/v1’, toggleRoutes);
// Global Error Handler (for better error responses)
app.use((err, req, res, next) => {
console.error(“Error:”, err);
res.status(500).json({ error: “Internal Server Error”, details: err.message });
});
app.listen(port, () => {
console.log(Server running on port ${port});
});
I’d really appreciate guidance from anyone who has handled a similar setup. Thank you!