mongoose-init-config
v1.0.10
Published
This module simplifies the initial setup of mongoose.
Downloads
5
Readme
mongoose-init-config
It is a module that helps mongoose to connect easily.
Installation
// Using npm
npm install -s mongoose-init-config
// Using yarn
yarn add mongoose-init-config
Prerequisite
You need an .env file in the root folder in the following format:
# .env
MONGO_URI_PROD=mongodb://localhost:27017/
MONGO_URI_DEV=mongodb://localhost:27017/
MONGO_DATABASE=example
Usage
Require the package from the index file.
// Using Node.js `require()`
const db = require('mongoose-init-config');
db();
// Using ES6 imports
import db from 'mongoose-init-config';
db();
If you are using express:
const express = require('express');
const app = express();
app.listen(3000, () => {
console.log('> Express server is running on port 3000');
db();
});
If you are using koa:
const Koa = require('koa');
const app = new Koa();
app.listen(3000, () => {
console.log('> Koa server is running on port 3000');
db();
});
If the db connection and the web server run successfully, you will see the following on the console:
# Using express
> Express server is running on port 3000
> Connected on
- URI: mongodb://127.0.0.1:27017/
- Database: TEST
- Environment: DEVELOPMENT
# Using koa
> Koa server is running on port 3000
> Connected on
- URI: mongodb://127.0.0.1:27017/
- Database: TEST
- Environment: DEVELOPMENT
Tests
// Using npm
npm install
npm test
// Using yarn
yarn
yarn test