my 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}`)
})
file for mongodb connection name as conn.js
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
my service has stopped and an error occur "Windows could not start the mongoDB server (mongoDB) service on local computer
Error 1067 : the process terminated unexpectedly
mongod
ifMongoDB
is running in your machine. check all these and let me know(Get-CimInstance Win32_Service -Filter 'Name = "mongoDB"').PathName
(name may differ)