My personal extensions for nodejs
- @mtsmachado8/errors
- @mtsmachado8/logger
- @mtsmachado8/repository
Módulo usado para Erros da Api
const AuthenticationFailed = require('@mtsmachado8/errors/authentication-failed-401');
throw new AuthenticationFailed();
this will throw a 401 error with a default message or
const AuthenticationFailed = require('@mtsmachado8/errors/authentication-failed-401');
throw new AuthenticationFailed('My custom AuthenticationFailed message');
import AuthenticationFailed from '@mtsmachado8/errors/authentication-failed-401';
throw new AuthenticationFailed();
this will throw a 401 error with a default message or
import AuthenticationFailed from '@mtsmachado8/errors/authentication-failed-401';
throw new AuthenticationFailed('My custom AuthenticationFailed message');
Módulo usado para logs da aplicação
const log = require('@mtsmachado8/logger');
log.info('message')
import log from '@mtsmachado8/logger';
log.info('message')
NODE_ENV || development LOG_LEVEL || silly
NODE_ENV -> usado para o formato do log (json para production e color para outros ambientes) LOG_LEVEL -> usado para identificar qual nível de mensagem logar
- silly
- info
- warn
- error
Módulo usado para conectar o mongodb + mongoose ao projeto de forma simples.
DATABASE_USER || ''
DATABASE_PASS || ''
DATABASE_HOST || '127.0.0.1'
DATABASE_PORT || '27017'
DATABASE_NAME || 'database'
DATABASE_SRV || false
import repository from '@mtsmachado8/repository'
repository.start()
.then(() => {
log.info('Connected to db')
})
.catch(e => {
log.info(`Error connecting to db: ${e}`)
})