iHub Framework
raw JSON → 2.2.3 verified Fri May 01 auth: no javascript
iHub Framework is a Node.js microservices framework designed for the iHub ecosystem. Version 2.2.3 is the current stable release. It provides tools for building microservices with Docker and Kubernetes, including graceful shutdown, environment variable configuration for project, Node.js environment, and logger settings (Elasticsearch and console). The framework is in active development (WIP) and is distributed via a private npm registry. It ships TypeScript types and is primarily used internally within Infracommerce.
Common errors
error Module not found: Can't resolve 'ihub-framework-ts' ↓
cause The package is only available in a private npm registry.
fix
Ensure you have .npmrc with registry=https://registry.infracommerce.com.br/repository/npm-local/ and have access.
error TypeError: Cannot read property 'start' of undefined ↓
cause Application or Logger not imported correctly.
fix
Use named imports: import { Application, Logger } from 'ihub-framework-ts'
Warnings
gotcha Framework requires a private npm registry (registry.infracommerce.com.br). You must have access to that registry to install the package. ↓
fix Create a .npmrc file pointing to the private registry.
gotcha Docker is required for development; local Node.js 8+ is discouraged but possible. ↓
fix Install Docker and Docker Compose and use them for development.
gotcha The framework uses a custom logger that expects Elasticsearch configuration. If not set, it may fail silently. ↓
fix Ensure LOGGER_ELASTICSEARCH_ENABLED is set to false if not using Elasticsearch.
Install
npm install ihub-framework-ts yarn add ihub-framework-ts pnpm add ihub-framework-ts Imports
- Application wrong
const Application = require('ihub-framework-ts').Applicationcorrectimport { Application } from 'ihub-framework-ts' - Logger wrong
import Logger from 'ihub-framework-ts'correctimport { Logger } from 'ihub-framework-ts' - Config wrong
import { Config } from 'ihub-framework-ts/Config'correctimport { Config } from 'ihub-framework-ts'
Quickstart
import { Application, Logger } from 'ihub-framework-ts';
const app = new Application({
projectName: process.env.PROJECT_NAME ?? 'my-service',
nodeEnv: process.env.NODE_ENV ?? 'development',
});
const logger = new Logger({
elasticsearch: {
enabled: process.env.LOGGER_ELASTICSEARCH_ENABLED === 'true',
url: process.env.LOGGER_ELASTICSEARCH_URL ?? '',
level: process.env.LOGGER_ELASTICSEARCH_LEVEL ?? 'info',
},
console: {
level: process.env.LOGGER_CONSOLE_LEVEL ?? 'debug',
},
});
app.use(logger);
app.start();