Shared nodejs lib with with reusable functions
npm install @openhealth/oht-custom-parser-liboht-custom-parser-lib is a shared library designed for use across multiple Node.js cloud functions. It contains common MongoDB connectors and data utilities that can be reused to avoid code duplication and ensure consistency.
- Installation
- Usage
- Development
- Patch Versions
- Publish to npm Registry
- Using the Library in Cloud Functions
To install oht-custom-parser-lib, you can add it as a dependency in your project using npm:
``bash`
npm install oht-custom-parser-lib
Or, if you want to install a specific version:
`bash`
npm install oht-custom-parser-lib@
After installing, you can import and use the library in your cloud functions:
`javascript`
const { connectToMongoDB } = require('oht-custom-parser-lib');
When making changes to the oht-custom-parser-lib, you need to update the version number before publishing. Follow these steps:
1. Update the version number: Use npm's version command to bump the version:
- Patch for bug fixes:
`bash`
npm version patch
`
- Minor for new features:
bash`
npm version minor
`
- Major for breaking changes:
bash`
npm version major
This command will automatically update the version in the package.json and create a git tag.
2. Commit Changes: Ensure your changes and the version bump are committed to the repository.
After updating the version, you can publish the library to the npm registry:
1. Login to npm (if you haven't already):
`bash`
npm login
2. Publish the package:
`bash`
npm publish
If this is a private package, use:
`bash`
npm publish --access restricted
3. Verify the publish: You can check the package on npmjs.com to verify that the new version is available.
To use oht-custom-parser-lib in your cloud functions:
1. Install the Library: Add oht-custom-parser-lib as a dependency in the cloud function's package.json:
`json`
{
"dependencies": {
"oht-custom-parser-lib": "^1.0.0"
}
}
Replace ^1.0.0 with the appropriate version as needed.
2. Install Dependencies: Run npm install` to install the library along with other dependencies.
3. Deploy Your Function: Deploy your cloud function as usual, ensuring that the updated dependencies are included.