It is a mistake the correct method is to show server running message on terminal only when db is connected. like this
mongoose.connect(process.env.URI,{
useNewUrlParser:true,
useUnifiedTopology:true,
useCreateIndex:true,
useFindAndModify:false})
.then(()=>{
app.listen(port,host,()=>{
console.log(http://${host}:${port});
})
console.log("Connected")
})
.catch((err)=>console.log(err))
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
why do you have
app.listen
in two places ?why?
Because we need to be connected to our DB in order to serve the data to the client when they send a http request
It is a mistake the correct method is to show server running message on terminal only when db is connected. like this
mongoose.connect(process.env.URI,{
useNewUrlParser:true,
useUnifiedTopology:true,
useCreateIndex:true,
useFindAndModify:false})
.then(()=>{
app.listen(port,host,()=>{
console.log(
http://${host}:${port}
);})
console.log("Connected")
})
.catch((err)=>console.log(err))