Я пытаюсь развернуть простой бэкэнд Express / Node в Heroku, однако он продолжает выдавать ошибку, что он не может найти модуль моего основного сервера, «не может найти модуль server. js», но это правильно в каталоге root.
Файл моего основного сервера:
const express = require("express");
const connectDB = require("./config/db");`enter code here`
const app = express();
const path = require("path");
const cors = require("cors");
// connect to DB
connectDB();
// Init middleware
app.use(
express.json({
extended: false,
})
);
app.use(express.static("./"));
app.use(cors());
app.get("/", (req, res) =>
res.json({
msg: "Welcome to the Pokedex API",
})
);
// defining routes
app.use("/api/users", require("./routes/users"));
app.use("/api/pokemon", require("./routes/pokemon"));
app.use("/api/auth", require("./routes/auth"));
let port = process.env.PORT;
if (port == null || port == "") {
port = 5000;
}
app.listen(port, () => {
console.log(`Pokemon server started successfully in port ${port}`);
});
Пакет. json
{
"name": "backend",
"version": "1.0.0",
"description": "Custom Pokedex App",
"main": "server.js",
"engines": {
"node": "10.16.0",
"npm": "6.9.0"
},
"scripts": {
"start": "node server.js",
"backend": "nodemon server/index.js",
"frontend": "npm run front --prefix client",
"dev": "concurrently \"npm run backend\" \"npm run start --prefix client\""
},
"keywords": [
"pokedex"
],
"author": "Max Deale",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"concurrently": "^5.2.0",
"config": "^3.3.1",
"cors": "^2.8.5",
"express": "^4.17.1",
"express-validator": "^6.4.0",
"jsonwebtoken": "^8.5.1",
"mongoose": "^5.9.10",
"nodemon": "^2.0.3"
}
}
Почему-то основной server.js
файл не найден, есть ли строка кода, которую мне не хватает, чтобы Heroku нашел ее в каталоге root?
Я также добавил procfile:
web: node server.js
, но постоянно получаю сообщение об ошибке.
Все отлично работает в разработке, и сейчас я пытаюсь развернуть бэкэнд только на Heroku с интерфейсом React на Netlify из-за постоянных проблем с развертыванием Heroku.