I was deploying my mern stack app to heroku, getting some kind of errors screenshot attached.
errors from activity logs: 2022-09-08T22:02:02.914114+00:00 app[web.1]: app is running at 35635 2022-09-08T22:02:02.914778+00:00 app[web.1]: Cannot read properties of null (reading 'split') 2022-09-08T22:02:03.072495+00:00 heroku[web.1]: Process exited with status 1 2022-09-08T22:02:03.137611+00:00 heroku[web.1]: State changed from starting to crashed 2022-09-08T22:06:33.637723+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/api/products" host=spiffy-shirts.herokuapp.com request_id=c6a06345-ab6b-4dbf-a76b-212dc9d9e81e fwd="27.4.164.92" dyno= connect= service= status=503 bytes= protocol=https
In my local env everything works fine.
My server index file code
// dependancy included: express,mongosse,cors,bodyParser, cookieParser ...
const app = express();
//DB
const connectDB = async () => {
try {
await mongoose.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
});
console.log('MongoDB is Connected...');
} catch (err) {
console.error(err.message);
process.exit(1);
}
};
connectDB();
//My routes
const authRoutes = require('./routes/auth');
//Middlewares
//bodyparser, cookieparser,cors ...
//PORT
const port = process.env.PORT || 6000;
//My routes
app.use('/api', authRoutes);
if (process.env.NODE_ENV === 'production') {
app.use(express.static('frontend/build'));
}
//Starting a Server
app.listen(port, () => {
console.log(`app is running at ${port}`);
});
