this is my server.js
const express = require("express");
const mongoose = require("mongoose");
mongoose.connect('mongodb://mongodata:27017/test1')
.then(()=>{console.log("DB connected")})
.catch((err)=>{console.log("Error in Db connection ",err)})
const app = express()
app.get('/', (req, res)=>{
res.status(200).json({data:"Hello world"})
})
app.listen(5000,()=>{
console.log("running on port 5000");
})
compose.yml
version: "3.9"
services:
mongodata:
image: "mongo:4.4.6"
app:
build: .
ports:
- "5000:5000"
Dockerfile
FROM node:alpine
WORKDIR /usr/expressmongo
COPY ./ ./
RUN npm install
CMD ["npm", "start"]
this code is running on my friend's system but when I run it using the docker compose up it throws the error