mongoose.connect(), first argument should be String, received undefined

前端 未结 21 2904
既然无缘
既然无缘 2021-02-12 15:55

I am trying to set the test database for the testing purpose, but its not working.

I am trying to connect to mongodb using mongoose, but finding problem in connection er

21条回答
  •  一生所求
    2021-02-12 16:23

    in case you've forgotten to import/require dotenv, then you can run dotenv before running your app using --require dotenv/config

    node --require dotenv/config index.js // regular node command
    
    // nodemon to restart application whenever a file gets changed
    nodemon --require dotenv/config index.js
    
    // integrate with babel-node if you're using latest JS features like import/export
    nodemon --require dotenv/config index.js --exec babel-node
    

    No need to require dotenv and call config function within codebase. Enjoy!

提交回复
热议问题