Error Cannot find module mongodb

0 votes

I am going through my first node.js project. I've installed mongodb, have a server.js file, and when I try to run it I get this error

module.js:340
    throw err;
         ^
Error: Cannot find module 'mongodb'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)

I am quite certain I have mongodb installed, I am new to unix coming from a C# windows background, but I think this is a path not being configured properly?

Oct 15, 2020 in Node-js by kartik
• 37,520 points
13,364 views

1 answer to this question.

0 votes

Hello @kartik,

The error you are getting indicates that the NPM package for MongoDB is not correctly installed.

The fix here depends on how you plan to leverage NPM. The NPM package manager operates has two different modes of operation: local and global.

The first (and default) mode is "local".

If you go to the folder with server.js you will see a sub-folder named node_modules. Under that folder will be a mongodb folder. If that folder is not present, then the mongodb module is not installed on that path.

To correct this, cd to that folder and type npm install mongodb. When the process is done you should have the node_modules/mongodb folder available.

You can also install MongoDB package globally using npm install -g mongodb. This is useful if you are using lots of node.js command-line stuff, but less useful if you are deploying the whole thing.

Hope this helps!!

To know more about Mongodb, go for Mongodb training online without fail.

Thanks!

answered Oct 15, 2020 by Niroj
• 82,840 points

Related Questions In Node-js

0 votes
1 answer

Error:Cannot find module 'xmlhttprequest'

Hello @kartik, XMLHttpRequest is a built-in object in web ...READ MORE

answered Sep 7, 2020 in Node-js by Niroj
• 82,840 points
7,263 views
0 votes
1 answer

Error: Cannot find module 'ejs'

Hello @kartik, Go up one level (above app.js) ...READ MORE

answered Sep 7, 2020 in Node-js by Niroj
• 82,840 points
10,531 views
0 votes
0 answers

Node.js Error: Cannot find module express

I have written a code for my ...READ MORE

May 9, 2022 in Node-js by Kichu
• 19,040 points
3,186 views
0 votes
1 answer
0 votes
1 answer

How to write files in Node.js?

Hello @kartik, Currently there are three ways to ...READ MORE

answered Jul 8, 2020 in Node-js by Niroj
• 82,840 points
934 views
0 votes
1 answer

How to Install a local module using npm?

Hello @kartik, This is what worked for me: npm ...READ MORE

answered Jul 9, 2020 in Node-js by Niroj
• 82,840 points
9,892 views
0 votes
1 answer

How to run Gulp tasks sequentially one after the other?

Hello @kartik, By default, gulp runs tasks simultaneously, ...READ MORE

answered Jul 12, 2020 in Node-js by Niroj
• 82,840 points
1,520 views
0 votes
1 answer

How to set environment variables from within package.json?

Hello @kartik, Set the environment variable in the ...READ MORE

answered Jul 13, 2020 in Node-js by Niroj
• 82,840 points
23,999 views
0 votes
1 answer

Error:Nodejs cannot find installed module on Windows

Hello @kartik, Add an environment variable called NODE_PATH and set ...READ MORE

answered Jul 15, 2020 in Node-js by Niroj
• 82,840 points
4,952 views
0 votes
1 answer

Error:NPM global install “cannot find module”

Hello @kartik, I got this error Error: Cannot find ...READ MORE

answered Jul 16, 2020 in Node-js by Niroj
• 82,840 points
16,496 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP