0

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

New contributor
Harshit Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
3
  • Which version of mongoose you are using? Options are no longer needed in Mongoose 6.x.You have defined mongoose connection code but have not executed the one in the main file. You can directly execute the connection code in your main file. Also check in your local machine by running mongod if MongoDB is running in your machine. check all these and let me know
    – Subha
    Commented Jul 5 at 7:22
  • In addition to the comment above check your firewall settings Commented 2 days ago
  • Have a look at the MongoDB logfile. Location of logfile is defined in Mongo config file. Location of config file you get with in Powershell with (Get-CimInstance Win32_Service -Filter 'Name = "mongoDB"').PathName (name may differ) Commented 2 days ago

0

Browse other questions tagged or ask your own question.