This repository has been archived by the owner on Sep 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
86 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters