npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mares-connector

v2.0.8

Published

mares framework connector

Downloads

9

Readme

mares-connector

mares framework 구동 모듈

Installation

npm install --save mares-connector

Example

//connector.js

const appRoot = require('app-root-path')

const settings = require('./')
const MaresConnector = require('mares-connector')
const maresMongoose = require('mares-mongoose')
const MaresWelder = require('mares-welder')
require('mares-mongoose-validator-extend') //단순로드
const maresExpressErrorHandler = require('mares-express-error-handler')
settings.global()

/**
 * App 연결 Connector
 */
class Connector {

	constructor() {

	}

	async start() {
		try {
			// mares-welder를 설정한다. (자세한 내용은 mares-welder문서를 참고한다.)
			this.mares = new MaresWelder(rootPath)
			this.mares.setMaresMongoose(maresMongoose)
			this.mares.bindExpressErrorHandler(maresExpressErrorHandler())
			
			// 설정된 mares를 아래와 같이 넣어준다.
			this.connector = new MaresConnector(this.mares, settings)
			await this.connector.startApp(appRoot.path)
			return this.connector
		} catch (e) {
			console.error(e)
		}
	}

	async stop() {
		
		// stopApp() 함수를 통해서 데이터베이스를 포함한 모든 서버 커넥션을 종료시킬 수 있다.
		await this.connector.stopApp()
	}
}

module.exports = Connector

Settings

index.js로 아래의 값들을 노출시킨다.

config

설정값을 세팅해준다. 0. index.js

  1. common.js
  2. development.js
  3. production.js
  4. test.js
{
    "mongoose": {
        "force": true,
        "url": "mongodb://localhost:27017/test?replicaSet=test"
    }
}

mongoose를 연결하기 위해선 mongoose 설정값을 반드시 넣어준다.

global

global 변수를 정의해준다.

module.exports = () => {
	global._ = require('lodash')
}

local

로컬라이제이션 스키마를 넣어준다.

let local = {
	'defaultLocale': 'KR',
	'defaultLanguage': 'ko',
	'locales': {
		'KR': {
			'name': '대한민국',
			'enName': 'Korea',
			'code': '+82',
			'timeGap': 9
		}
	},
	'languages': {
		'ko': {
			'name': '한국어',
			'enName': 'KOREAN',
			'countries': ['KR']
		}
	}
}
module.exports = local

modules

연결해야 할 모듈이름을 배열로 적어준다.

module.exports = [
    'infra-message'
]

mongoose or sequelize

데이터베이스 연결을 수행한다.

const mongoose = require('mongoose')
const meta = require('../infra-message/infra/meta')
const config = require('../settings/config').mongoose

require('./validator')
mongoose.set('useCreateIndex', true)
mongoose.plugin(require('mongoose-paranoid-plugin'), {field: 'delAt'})
mongoose.plugin(require('mongoose-beautiful-unique-validation'))
mongoose.plugin((schema, options = {}) => {
	schema.post('validate', function (error, doc, next) {
		Object.values(error.errors)
			.filter(fieldError => fieldError.name === 'CastError')
			.forEach(fieldError => {
				fieldError.message = options.messageKey || 'error.common.cast'
			})
		next(error)
	})
}, {
	messageKey: meta.codes.invalidType
})

module.exports = (async () => {
	return await mongoose.connect(config.url, {useNewUrlParser: true})
})