node.js cannot find module 'mongodb'

前端 未结 11 2055
天涯浪人
天涯浪人 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:57

    After trying for some time to install it without success (since I'm new to mongo and node), I was missing the npm link step indeed. So just to summarize, I did this:

    1. npm install mongodb -g
    2. cd /path/to/my/app/folder
    3. npm link mongodb

    With that in place, I could do this in my application file: require('mongodb').

    Here are some references, in case you need them:

    • npm global vs local
    • npm link
    • Introduction to Mongo DB

提交回复
热议问题