Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
readme files
Browse files Browse the repository at this point in the history
  • Loading branch information
borisovg committed Apr 30, 2024
1 parent 98131c3 commit 7cf067a
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 10 deletions.
18 changes: 13 additions & 5 deletions packages/core-express/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
# @101-ways/core-express

[Express](https://expressjs.com/) server accelerator packages. It uses the Service Registry pattern to create a single object with APIs.
[Express](https://expressjs.com/) server accelerator package. It uses the Service Registry pattern to create a single object with APIs.

## Features

- starts server on port 8000 by default
- request / response logging with tracing metadata
- [asynchronous context](https://nodejs.org/api/async_context.html) within request flow

## Usage

```ts
import { load } from '@101-ways/core-express';

loadCore([`${__dirname}/modules`]).then((sr) => {
console.log('SERVICE REGISTRY', sr);
load([`${__dirname}/modules`]).then((sr) => {
sr.express.app.get('/hello', (req, res) => {
res.json({ result: 'hello world' });
});
});
```

Basic example for creating a child package:

```ts
import { load as loadCore, type Registry } from '@101-ways/core';
import { load as loadCore, type Registry } from '@101-ways/express';

export type { Registry };

Expand All @@ -28,7 +36,7 @@ export async function load<T extends Registry>(paths: string[] = [], sr?: T) {

Everything in [@101-ways/core](../core/README.md) and

- sr.config - configuration ([link](./src/modules/config.ts#14))
- sr.config - configuration (see [./src/modules/config.ts](./src/modules/config.ts))
- sr.express - Express module methods
- sr.express.app - Express app (see https://expressjs.com/en/4x/api.html#app)
- sr.express.returnError(req, res, err, code?) - helper function to log and return an error
Expand Down
25 changes: 25 additions & 0 deletions packages/core-mongo-express/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
# @101-ways/core-mongo-express

Express + MongoDB accelerator package. It uses the Service Registry pattern to create a single object with APIs.

## Usage

```ts
import { load } from '@101-ways/core-mongo-express';

load([`${__dirname}/modules`]).then((sr) => {
const collection = sr.mongo.db().collection('test');

sr.express.app.get('/hello', async (req, res) => {
const results = await collection.find({}).toArray();
res.json({ results });
});
});
```

## Service Registry API

Combination of [@101-ways/core-express](../core-express/README.md) and [@101-ways/core-mongo](../core-mongo/README.md).

## Environment Variables

Combination of [@101-ways/core-express](../core-express/README.md) and [@101-ways/core-mongo](../core-mongo/README.md).
45 changes: 45 additions & 0 deletions packages/core-mongo/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,46 @@
# @101-ways/core-mongo

[MongoDb](https://www.mongodb.com/) client accelerator package. It uses the Service Registry pattern to create a single object with APIs.

## Features

- starts server on port 8000 by default
- debug logging with tracing metadata

## Usage

```ts
import { load } from '@101-ways/core-mongo';

load([`${__dirname}/modules`]).then(async (sr) => {
const collection = sr.mongo.db().collection('test');
const list = await collection.find({}).toArray();
console.log(list);
sr.core.shutdown.run();
});
```

Basic example for creating a child package:

```ts
import { load as loadCore, type Registry } from '@101-ways/core-mongo';

export type { Registry };

export async function load<T extends Registry>(paths: string[] = [], sr?: T) {
return loadCore([`${__dirname}/modules`, ...paths], sr);
}
```

## Service Registry API

Everything in [@101-ways/core](../core/README.md) and

- sr.config - configuration (see [./src/modules/config.ts](./src/modules/config.ts))
- sr.mongo - MongoDB client (see https://mongodb.github.io/node-mongodb-native/6.5/classes/MongoClient.html)

## Environment Variables

Everything in [@101-ways/core](../core/README.md) and

- MONGO_URI='mongodb://localhost:27017/test' - Mongo connection URI
4 changes: 1 addition & 3 deletions packages/core-mongo/src/modules/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { config as coreConfig } from '@101-ways/core';

import { Registry } from '../types';

const { MONGO_DB = 'test', MONGO_URI = 'mongodb://localhost:27017/test' } =
process.env;
const { MONGO_URI = 'mongodb://localhost:27017/test' } = process.env;

export function $onBind(sr: Registry) {
sr.config = config;
Expand All @@ -12,7 +11,6 @@ export function $onBind(sr: Registry) {
export const config = {
...coreConfig,
mongo: {
db: MONGO_DB,
uri: MONGO_URI,
},
};
4 changes: 2 additions & 2 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Base package for building accelerator packages. It uses the Service Registry pat
```ts
import { load } from '@101-ways/core';

loadCore([`${__dirname}/modules`]).then((sr) => {
load([`${__dirname}/modules`]).then((sr) => {
console.log('SERVICE REGISTRY', sr);
});
```
Expand All @@ -26,7 +26,7 @@ export async function load<T extends Registry>(paths: string[] = [], sr?: T) {

## Service Registry API

- sr.config - configuration ([link](./src/modules/config.ts#14))
- sr.config - configuration (see [./src/modules/config.ts](./src/modules/config.ts))
- sr.core - inherited from `@borisovg/service-core` package (see https://github.com/borisovg/node-service-core/blob/main/src/types.ts#L6)
- sr.ctx - [asynchronous context](https://nodejs.org/api/async_context.html) methods
- sr.ctx.get() - get current context
Expand Down

0 comments on commit 7cf067a

Please sign in to comment.