![]() Now, you can easily set up it and make a lightweight application. This example is enough to understand the MongoDB connection. Suppose that you have to use database.js the file in routes/index.js, you will have to include it as require('./database') You can use database.js file in multiple files by including them with require() the module. If you miss anything in this script, it will not work and produce an error. But make sure that your database name is already created in the mongo compass. Now you can use the script of the above file anywhere in your application. nnect('mongodb://localhost:27017/test', ) Ĭonsole.log('database is connected successfully') Ĭonsole.log('database is disconnected successfully') Ĭonn.on('error', (console, 'connection error:'))
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |