@ronatilabs/narango v1.1.0
Installation
npm i @ronatilabs/narangoThis package has multiple peer dependencies and expects your project to have them installed:
@nestjs/common@nestjs/corearangojs
Check the package.json to know the version range.
Usage
Import NarangoModule
This package exports a NestJS module for you to import in your application:
import { Module } from "@nestjs/common";
import { NarangoModule } from "@ronatilabs/narango";
import { MyService } from "./my-service.service";
@Module({
imports: [
NarangoModule.register({
database: {
url: "http://localhost:8529",
databaseName: "MyDatabase",
auth: {
username: "userDB",
password: "secretPassword",
},
},
}),
],
providers: [MyService],
})
export class MyAppModule {}For sake of simplicity the database credentials are passed directly to the register function in the example but in a production environment you'd want to use @nestjs/config instead.
NarangoModule can be registered as a global module through the global option:
imports: [
NarangoModule.register({
global: true,
database: {
url: "http://localhost:8529",
databaseName: "MyDatabase",
auth: {
username: "userDB",
password: "secretPassword",
},
},
}),
],Async registration
If you need to use providers to provide the options to Narango module, you can use NarangoModule.registerAsync:
import { Module } from "@nestjs/common";
import { NarangoModule } from "@ronatilabs/narango";
import { ConfigModule, ConfigService } from "@nestjs/config";
@Module({
imports: [
ConfigModule.forRoot(),
NarangoModule.registerAsync({
useFactory: (config: ConfigService) => ({
database: {
url: config.get<string>("url"),
databaseName: config.get<string>("databaseName"),
auth: {
username: config.get<string>("username"),
password: config.get<string>("password"),
},
},
}),
inject: [ConfigService],
}),
],
})
export class MyAppModule {}Inject NarangoService
Now you can access the NarangoService everywhere you need it in your application:
import { Injectable } from "@nestjs/common";
import { NarangoService } from "@ronatilabs/narango";
@Injectable()
export class MyService {
constructor(private narango: NarangoService) {}
async myMethod() {
const collections = await this.narango.db._collections();
// do whatever you want
}
}Contribute
All contributions are welcome!
Local setup
There is a .nvmrc file at the project root which indicates the current version used to develop. It works with nvm which is a tool to help you manage the different node versions you're using. If you don't already use it, we highly recommend you to give it a try.
Commit format
This project is setup with automatic semver versioning based on your commit semantic. It uses commitizen to enforce the format and help contributors format their commit message. We follow the conventional commit format. Once you want to commit your work, you need to:
git addthe changes you want to commit.- Run
npx czto start the commitizen CLI. - Follow along the wizard to create your commit.
- Push your commit on the branch.
- Create your PR.
Notes for project's maintainers
When you merge a PR from beta into main and it successfully published a new version on the latest channel, don't forget to create a PR from main to beta. This is mandatory for semantic-release to take it into account for next beta version.
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago