1.0.10 • Published 6 years ago

mongoose-init-config v1.0.10

Weekly downloads
36
License
MIT
Repository
github
Last release
6 years ago

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

License

MIT

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago