DEV Community

Cover image for Docker: NodeJs and MongoDb Services

Docker: NodeJs and MongoDb Services

Abayomi Ogunnusi on May 10, 2022

Hello there, This post is a continuation of my docker article. To check click the links. Docker in and out Dockerize NodeJs app To follow along, ...
Collapse
 
zahakhussain profile image
Muhammad Zahak

I couldn't done this. is the documentation correct or something missing or not guided according to the beginner level ?

Collapse
 
chandrashekhar profile image
Chandrashekhar Mehta

Everything is correct; just follow the steps. Did you install Node and Docker?

Collapse
 
zahakhussain profile image
Muhammad Zahak

yes, but when I run localhost to check docker container it is not respond and when I run command 'npm start' the other port for node is running.

Thread Thread
 
chandrashekhar profile image
Chandrashekhar Mehta

Yes, actually, there is a problem with the Mongoose file db.js

`const mongoose = require('mongoose');
const mongoURI = "mongodb://localhost:27017"

const connectDb = async () => {
try {
mongoose.set('strictQuery', false)
mongoose.connect(mongoURI)
console.log('Mongo connected')
}
catch(error) {
console.log(error)
process.exit()
}
}
module.exports = connectDb;
`

try this code instead.
hope this will help to resolve.

Thread Thread
 
zahakhussain profile image
Muhammad Zahak

C:\Users\zahak\OneDrive\Desktop\webApp\node_modules\express\lib\router\index.js:469
throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
^

TypeError: Router.use() requires a middleware function but got a Object
at Function.use (C:\Users\zahak\OneDrive\Desktop\webApp\node_modules\express\lib\router\index.js:469:13)
at Function. (C:\Users\zahak\OneDrive\Desktop\webApp\node_modules\express\lib\application.js:227:21)
at Array.forEach ()
at Function.use (C:\Users\zahak\OneDrive\Desktop\webApp\node_modules\express\lib\application.js:224:7)
at Object. (C:\Users\zahak\OneDrive\Desktop\webApp\app.js:18:5)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint as runMain

Now this error I'm facing

Thread Thread
 
chandrashekhar profile image
Chandrashekhar Mehta

send your app.js and user.js file to me, there's probably problem with your routes

Thread Thread
 
zahakhussain profile image
Muhammad Zahak

how ? where ?

Thread Thread
 
chandrashekhar profile image
Chandrashekhar Mehta

can you push it on your github ?

Thread Thread
 
zahakhussain profile image
Muhammad Zahak

doing

Thread Thread
 
zahakhussain profile image
Muhammad Zahak

pushed Code, have you seen yet ?

Thread Thread
 
chandrashekhar profile image
Chandrashekhar Mehta

Sorry, bro, I was busy for a few days. couldn't see it; I even didn't get this notification. Will see and let you know asap.

Collapse
 
chandrashekhar profile image
Chandrashekhar Mehta

Thank you very much! for creating this
It's very helpful to me while doing a course on Coursera. You have created such an easy way to perform the steps.

Collapse
 
zahakhussain profile image
Muhammad Zahak

is your code run ?

Collapse
 
chandrashekhar profile image
Chandrashekhar Mehta

yes

Thread Thread
 
zahakhussain profile image
Muhammad Zahak

How kindly explain so that I can sort out, it is not running when I run command 'npm start'

Thread Thread
 
chandrashekhar profile image
Chandrashekhar Mehta

send your discord user name, I will connect with you and explain or if you can explain your problem here in detail

Thread Thread
 
Sloan, the sloth mascot
Comment deleted
 
chandrashekhar profile image
Chandrashekhar Mehta

your github repo has nothing to solve

Collapse
 
zahakhussain profile image
Muhammad Zahak

C:\Users\zahak\OneDrive\Desktop\webApp\node_modules\express\lib\router\index.js:469
throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
^

TypeError: Router.use() requires a middleware function but got a Object
at Function.use (C:\Users\zahak\OneDrive\Desktop\webApp\node_modules\express\lib\router\index.js:469:13)
at Function. (C:\Users\zahak\OneDrive\Desktop\webApp\node_modules\express\lib\application.js:227:21)
at Array.forEach ()
at Function.use (C:\Users\zahak\OneDrive\Desktop\webApp\node_modules\express\lib\application.js:224:7)
at Object. (C:\Users\zahak\OneDrive\Desktop\webApp\app.js:18:5)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint as runMain

I got this error

Collapse
 
chandrashekhar profile image
Chandrashekhar Mehta

added two files to your repository.