node.jsmongodbexpressejsrailway

Trying to host on Railway but get Error: Cannot find module './models/product'


Railway error

1

I decided to host my website(made on express.js) on railway. But i get Error: Cannot find module './models/product'. Even if it works on localhost

How directory looks

2

Why this is happening ? And how can i fix it ?

But this wont happen on localhost. And no matter how ill try to change path to index.js it won`t work.


Solution

  • The problem was when choosing the PORT to connect. Railway.com hosting needs an .env variable to choose which port to use. I hadn't written this, so hosting returned an error. This is how it was resolved:

    app.listen(process.env.PORT || 3000, () => {
        console.log("On work")
    })