node.js cannot find module 'mongodb'

前端 未结 11 2072
天涯浪人
天涯浪人 2020-12-07 22:36

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
    thro         


        
11条回答
  •  时光取名叫无心
    2020-12-07 22:49

    Install mongodb globally with below steps :-

    a) npm install mongodb -g

    b) Go to your app directory, where module.js is located and then run

    npm link mongodb

    Explanation :- When you install a package globally via npm, it is downloaded to global node_module folder. For me(Mac user), it's under /usr/local/lib/node_modules/mongodb. We link this to that directory from where you are trying to run module.js.

提交回复
热议问题