Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jarenal/wait4mongodb
Wait For MongoDB is a little NodeJS module that will execute a task as soon MongoDB is ready. Very useful for multi container environments like Docker Compose.
https://github.com/jarenal/wait4mongodb
callback docker docker-compose interval mongo mongod mongodb mongodb-database nodejs timeout wait-for-it
Last synced: 18 days ago
JSON representation
Wait For MongoDB is a little NodeJS module that will execute a task as soon MongoDB is ready. Very useful for multi container environments like Docker Compose.
- Host: GitHub
- URL: https://github.com/jarenal/wait4mongodb
- Owner: jarenal
- License: isc
- Created: 2018-04-21T13:36:10.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-29T17:18:25.000Z (over 6 years ago)
- Last Synced: 2024-10-29T22:02:24.090Z (22 days ago)
- Topics: callback, docker, docker-compose, interval, mongo, mongod, mongodb, mongodb-database, nodejs, timeout, wait-for-it
- Language: JavaScript
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wait4MongoDB
Wait For MongoDB is a little NodeJS module that will execute a task as soon MongoDB is ready. Very useful for multi container environments like Docker Compose.
## Installing
Execute the next command line for to install the module using npm.
```
npm install wait4mongodb --save
```## Running the tests
Run the tests using the next command.
```
npm test
```## Usage
### Parameters
```javascript
wait4mongodb.tryConnect(url, times, interval, [options], [callback]);
````* **url**: The connection URI string
* **times**: How many times will try to connect.
* **interval**: Time in milliseconds between retries.
* **options (optional)**: MongoClient settings. See [MongoClient documentation](http://mongodb.github.io/node-mongodb-native/3.0/api/MongoClient.html) for more info.
* **callback (optional)**: Callback function.### Using callbacks
```javascript
const wait4mongodb = require('wait4mongodb');/* The next example will try to connect to MongoDB 20 times (every 500 milliseconds)
* and will return a timeout (if MongoDB is down) after 10 sec.
*/
wait4mongodb.tryConnect('mongodb://localhost:27017', 20, 500, {poolSize: 3}, (err, client) => {
if (err) {
console.log('MongoDB timeout');
} else {
console.log('MongoDB is ready!');
// You will have available MongoDB client from here.
}
});
```### Using Promises
```javascript
const wait4mongodb = require('wait4mongodb');/* The next example will try to connect to MongoDB 20 times (every 500 milliseconds)
* and will return a timeout (if MongoDB is down) after 10 sec.
*/
wait4mongodb.tryConnect('mongodb://localhost:27017', 20, 500, {poolSize: 3}).then(client => {
console.log('MongoDB is ready!');
// You will have available MongoDB client from here.
}).catch(err => {
console.log('MongoDB timeout');
});
```## Authors
* **Jose Antonio** - *Initial work*
## Donations
If you found this useful. Please, consider support with a small donation:
* **BTC** - 1PPn4qvCQ1gRGFsFnpkufQAZHhJRoGo2g5
* **BCH** - qr66rzdwlcpefqemkywmfze9pf80kwue0v2gsfxr9m
* **ETH** - 0x5022cf2945604CDE2887068EE46608ed6B57cED8## License
This project is licensed under the ISC License - see the [LICENSE](LICENSE) file for details
## Acknowledgments
* Project inspired on [arunoda/wait-for-mongo](https://github.com/arunoda/wait-for-mongo).