@santospatrick/notify
v0.0.4
Published
Effortless Email and SMS Notification System using Third-Party Providers with Node.js
Downloads
7
Readme
@santospatrick/notify
This library provides an easy-to-use notification system that supports sending notifications via email and SMS using third-party providers.
Disclaimer: This library is currently in alpha version and should not be used in production environments. Use it at your own risk.
Table of Contents
Features
- [x] Send Email notifications
- [ ] Send SMS notifications
- [x] Centralized notification management
- [x] Flexible architecture for extending to other notification channels
Installation
You can install this library using any of the following package managers:
Using npm
npm install @santospatrick/notifyUsing yarn
yarn add @santospatrick/notifyUsing pnpm
pnpm add @santospatrick/notifyUsage
Example: Sending an email
Here’s a basic example of how to send an email using the NotificationManager from the library:
Configuration: Setting up NotificationManager
First, create a file named notificationConfig.ts to configure the NotificationManager:
// notificationConfig.ts
import { NotificationManager, EmailProviders } from '@santospatrick/notify';
// Create a new instance of NotificationManager
const notificationManager = new NotificationManager();
// Setup email service to use Twilio SendGrid (more to come!)
notificationManager.addEmailService({
provider: EmailProviders.SENDGRID,
apiKey: 'YOUR_API_KEY_HERE', // Your Twilio SendGrid API key that starts with "SG."
});
export { notificationManager };Usage: Sending an email
Now, create another file named sendEmail.ts to use the notificationManager object for sending an email:
// sendEmail.ts
import { notificationManager } from './notificationConfig';
// Send notification
notificationManager
.send({
from: '[email protected]', // Needs to be a "Single Sender" verified in SendGrid.
to: '[email protected]',
subject: 'Hello from my application!',
html: '<strong>Hi there! Using @santospatrick/notify lib.</strong>',
})
.then(() => {
console.log('Email sent!');
})
.catch((error) => {
console.error(error);
});Third-Party Providers
Email Providers
How to get Twilio Sendgrid Grid API Key
This library uses SendGrid to send email notifications. To set up the SendGrid API key:
- Sign up for a Twilio SendGrid account.
- Go to
Settings > Sender Authentication > Verify a Single Sender > "Create New Sender". - Fill out the form and click "Create".
- Go to
Settings > API Keys > "Create API Key". - Give it a name and select "Restricted Access", click "Mail Send" and enable "Mail Send" (this is the only permission needed).

- Click "Create & View" and copy the API key.
Local Development
To test the library locally while developing, you can use npm link. This allows you to symlink your local development version of the library into another project.
Step-by-Step Guide
- In the root directory of your library, run:
npm linkThis will create a global symlink to your library.
- In the project where you want to test the library, run:
npm link @santospatrick/notifyThis will create a symlink from the global @santospatrick/notify to the node_modules of your project.
Make changes to this library and run
yarn buildto compile the TypeScript code.Run your project and test the changes.
Publishing to npm, yarn and pnpm
To publish the library to npm, follow these steps:
- Ensure your code is ready for publishing by running the build command:
yarn build- Update the version number in the
package.jsonfile.
{
"version": "0.0.3" // Next version to be published
}- Once the build is successful, publish the package to npm with public access:
npm publish --access publicThis will publish your library to the npm registry, making it available for others to install and use.
Made with ❤️ by Patrick Santos
