Heroku is showing application error when deploying from github repository , Here is package.json
{
"name": "tinder-backend",
"version": "1.0.0",
"description": "",
"main": "server.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.17.1",
"mongoose": "^5.11.15"
}
}
But it always shows Application error on heroku I added gitignore to excude node_modules Here is my code (not mine but learning express from youtube --> server.js) :
import express from 'express'
import mongoose from 'mongoose'
import Cors from 'cors'
import Cards from './dbCards.js'
// App Config
const app = express();
const port = process.env.port || 8001
const connection_url = `mongodb://admin:<hidden>@cluster0-shard-00-00.7vrlv.mongodb.net:27017,cluster0-shard-00-01.7vrlv.mongodb.net:27017,cluster0-shard-00-02.7vrlv.mongodb.net:27017/<hidden>?ssl=true&replicaSet=atlas-p4781z-shard-0&authSource=admin&retryWrites=true&w=majority`
//Middlewares
app.use(express.json())
app.use(Cors())
//DB config
mongoose.connect(connection_url,{
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true,
})
//api ENDPOINTS
app.get('/',(req,res)=>{
res.status(200).send('Hello world')
});
app.post('/tinder/card',(req,res) => {
const dbCard = req.body;
Cards.create(dbCard,(err,data) => {
if(err){
res.status(500).send(err)
}
else{
res.status(201).send(data)
}
})
});
app.get('/tinder/card',(req,res) => {
const dbCard = req.body;
Cards.find((err,data) => {
if(err){
res.status(500).send(err)
}
else{
res.status(200).send(data)
}
})
});
//listener
app.listen(port,()=> console.log(`listening on localhost:${port}`));
This works perfectly on local machine , beginner here any help will be appreciated
Here is the log which i see inside activity :
-----> Building on the Heroku-20 stack
-----> Node.js app detected
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=true
-----> Installing binaries
engines.node (package.json): unspecified
engines.npm (package.json): unspecified (use default)
Resolving node version 14.x...
Downloading and installing node 14.15.4...
Using default npm version: 6.14.10
-----> Restoring cache
- node_modules
-----> Installing dependencies
Installing node modules
added 83 packages in 2.08s
-----> Build
-----> Caching build
- node_modules
-----> Pruning devDependencies
audited 83 packages in 1.059s
2 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
-----> Build succeeded!
-----> Discovering process types
Procfile declares types -> (none)
Default types for buildpack -> web
-----> Compressing...
Done: 34.2M
-----> Launching...
Released v6
heroku logs -tto tail the logs. If you don't want to install it, you can view the logs from the Heroku web app.