Below is my implementation:
main file
const express = require("express");
const path = require("path");;
const app = express();
const hbs = require("hbs");
require("./db/conn")
const port = process.env.PORT || 3000 ;
const static_path = path.join(__dirname,"../public");
const template_path = path.join(__dirname,"../templates/views");
const partials_path = path.join(__dirname,"../templates/partials");
app.use(express.static(static_path))
app.set("view engine", "hbs");
app.set("views",template_path);
hbs.registerPartials(partials_path);
app.get("/" , (req,res)=> {
res.render("index")
}
);
app.listen(port, () => {
console.log(`server is running at port no ${port}`)
})
conn.js file for mongodb connection
const mongoose = require("mongoose");
mongoose.connect("mongodb://localhost:27017/youtubeRegistration" , {
// useNewUrlParser : true,
// useUnifiedTopology: true,
// useCreateIndex : true
}).then(() =>{
console.log(`connection successful`);
}).catch((e)=>{
console.log(`no connection ${e}`)
})
error
no connection MongooseServerSelectionError: connect ECONNREFUSED ::1:27017, connect ECONNREFUSED 127.0.0.1:27017
service stopped with the following error:
Windows could not start the mongoDB server (mongoDB) service on local computer
Error 1067 : the process terminated unexpectedly
2
Answers
Go to Win Services and look for MongoDB Server (MongoDB)
Disable it .. then restart the service
Here is your revised conn.js file
Below is your modified MainFile
Troubleshooting steps:
mongoose.connect('mongodb://localhost:27017/yourDatabaseName', { useNewUrlParser: true, useUnifiedTopology: true });
"C:Program FilesMongoDBServer<version>binmongod.exe" --dbpath "C:datadb"