GithubHelp home page GithubHelp logo

i5ting / mongooseconfig Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 15 KB

load mongoose connnection from config file for all Node.js web framework(express, koa)

Home Page: https://github.com/i5ting/mongooseconfig

License: MIT License

JavaScript 100.00%

mongooseconfig's Introduction

mongooseconfig

npm version

老婆说“看不过后台php那货写的代码,想自己学学”,于是让我教她mongoose,我才发现原来用了这么久的mongoose,竟然每次都要手写连接,然后再调用,可是手写里面也是有很多坑的,作为一个初学者的她是很难搞定的,于是就有了这个库

Features

  • 无需自己创建连接,用的时候创建配置文件即可
  • 处理了SIGTERM事件,即Node process ends,会自动关闭连接,避免mongodb连接数过多,导致服务器假死
  • 在npm postinstall之后,创建config/mongodb.example.js(如果不存在的话),提示用户修改“cp config/mongodb.example.js config/mongodb.js”
  • 如果不存在config/mongodb.js,这是读取node_modules/mongooseconfig/config/mongodb.js

Install

npm install --save mongooseconfig

Usages

最简单的用法

在app.js(无论是express or koa1 or koa2,还是其他框架)的第一行增加

require('mongooseconfig')()

它会自动创建 config/mongodb.example.js, 你只需复制一份即可

cp config/mongodb.example.js config/mongodb.js

自定义配置路径

在app.js(无论是express or koa1 or koa2,还是其他框架)的第一行增加

require('mongooseconfig')(__dirname + '/myconfig/db.js')

这样它就会加载用户指定的自定义配置路径了

配置项

module.exports = {
  "host": "127.0.0.1",
  "port": "27017",
  "db": "mongoose-config-demo",
  "is_debug":true
};

稍后会加

  • native_parser: true
  • auto_reconnect: true,
  • poolSize: 10
  • is_debug: true

示例

https://github.com/i5ting/mongooseconfig-example

Dev

npm start

Test

npm test

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

版本历史

  • v1.0.0 初始化版本

欢迎fork和反馈

如有建议或意见,请在issue提问或邮件

License

this repo is released under the MIT License.

mongooseconfig's People

Contributors

i5ting avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.