How can I use expressjs staticfiles after deploying backend app on Railway?

38 Views Asked by At

In the code images add to the /static folder, but where can I get the elements from this folder with Railway?

const models = require("./models");
const router = require("./routes");
const errorHandler = require("./middleware/errorHandlingMiddleware");

const cors = require("cors");
const express = require("express");
const fileUpload = require("express-fileupload");
const path = require("path");
require("dotenv").config();

const app = express();
app.use(cors());
app.use(express.json());
app.use(express.static(path.resolve(__dirname, "static")));
app.use(fileUpload({}));
app.use("/api", router);

// errors
app.use(errorHandler);

const PORT = process.env.PORT || 5000;

const startServer = async () => {
  try {
    await sequelize.authenticate();
    await sequelize.sync();
    app.listen(PORT, "0.0.0.0", () => {
      console.log("http://localhost:" + PORT);
    });
  } catch (error) {
    console.log(error);
  }
};

startServer();

It is my index.js file where all staticfiles is stored in the /static folder. I just want to know how to get static files in Railway.

I didn't find this information anywhere.I would be glad if you help me find the answer to my unusual question.

0

There are 0 best solutions below