Hi everyone,
I am connecting my pc with mongoDB on ubuntu server,
Everything works fine on my machine, which means when I type yarn start
my node app returns as DB-Connect
,
But on the server, it keeps saying connect ECONNREFUSED 127.0.0.1:27017
, I have researched for more than 4 hours but still no results
Hope anyone can help me,
Thanks
this is my file env
MONGO_USERNAME = 'trungpham'
MONGO_PASSWORD = 'something'
MONGO_HOSTNAME = '127.0.0.1'
MONGO_PORT = '27017'
MONGO_DB = 'furniture'
this is my code
const url = `mongodb://${process.env.MONGO_USERNAME}:${process.env.MONGO_PASSWORD}@${process.env.MONGO_HOSTNAME}:${process.env.MONGO_PORT}/${process.env.MONGO_DB}?authSource=admin`;
mongoose.connect(url,{useNewUrlParser: true})
.then((res)=> console.log(">>>>>DB connected"))
.catch((err)=> console.error("Connect fail", err));
this is log on server