npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aw-notifications

v0.0.1

Published

A NPM package that provide notifications functionality to send emails and sms by using nodemailer and twilio.

Downloads

5

Readme

CC-Notifications

a package use to send email notifications by using mailgun, mailtrap, sendgrid and sms notifications by using twilio.

Installation

Install cc-notifications with npm

npm i cc-notifications
npm install cc-notifications

Enter the path of the folder where handlebars template are placed.
Enter .handlebars template folder path: template_folder

Environment Variables

To run this package, you will need to add the following environment variables to your .env file

For Email
EMAIL_FROM
EMAIL_SMTP
EMAIL_PORT
EMAIL_USER
EMAIL_PASSWORD

For SMS
SMS_ACCOUNT_SID
SMS_AUTH_TOKEN
SMS_SERVICE_SID

Usage Overview

The given functions can be used in any .js file. The starter index.js file or any other.

Sending Email

const { sendMail } = require("cc-notifications");
sendMail({
  to: "[email protected]",
  subject: "This is an Email",
  body: `<h1>this is an email.</h1>`,
}).then((res) => {
  //return email_id if success else return error message
});

or

const { sendMail } = require("cc-notifications");

async function email() {
  let res = await sendMail({
    to: "[email protected]",
    subject: "This is an Email",
    body: `<h1>this is an email.</h1>`,
  });
  //res contains email_id if success or error message if fail.
}

email();

Sending SMS

const { sendSMS } = require("cc-notifications");
sendSMS({
  to: "+92300*******",
  body: "this is an text sms.",
}).then((res) => {
  //return msg_id if success else return error message
});

or

const { sendSMS } = require("cc-notifications");

async function sms() {
  let res = await sendSMS({
    to: "+92300*******",
    body: "this is an text sms.",
  });
  //res contains sms_id if success or error message if fail.
}

sms();

Options

email object constructor options:

| Props | Option | Description | Example | | ------------ | -------- | ------------------------------------------------------------------------------------------ | ----------------------------------------------------- | | to | required | recipient email address or array of comma separated multiple recipient email addresses | to: "[email protected]" | | body | required | custom raw html or handlebars template name | body: "<h1>Email</h1>" | | subject | optional | email subject line | subject: "Email Subject Line" | | cc | optional | cc recipient email address or array of comma separated multiple recipient email addresses | cc: ["[email protected]","[email protected]"] | | bcc | optional | bcc recipient email address or array of comma separated multiple recipient email addresses | bcc: "[email protected]" | | context | required | (handlebars) handlebars template attributes | see more | | attachment | optional | send attachment with an email | see more | | priority | optional | priority for sending email, I.e. high, normal (default) or low | priority: "high" | | replyTo | optional | recipient email address for default reply-to | replyTo: "Email Subject Line" | | text | optional | plaintext message text | text: "Email Text Line" |

sms object constructor options:

| Props | Option | Description | Example | | ------ | -------- | ---------------------- | -------------------------------------- | | to | required | recipient phone number | to: "+92300*******" | | body | required | sms body text | body: "Hello you got a new message." |

Usage/Email Options

body html raw template

{
    body: `<div>
        <h1>welcome User</h1>
        <a href="#">Activate Email</a>
    </div>`,
}

email handlebar template

create and save the templates in project level cc-notifications_views folder with .handlebars extension and call name with extension

project-name/cc-notifications_views/template_name.handlebars

{
    body: "template_name.handlebars",
}
email handlebar template context

project-name/cc-notifications_views/template_name.handlebars

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
    <h1>Welcome {{ username }} !</h1>
    <p>{{ body }}</p>
    <a href="{{ link }}" target="_blank">GET START</a>\
</body>
</html>
{
    body: "template_name.handlebars",
    context: {
        username: "User Name",
        link: "www.url-link.com",
        body: "this is body paragraph.",
    },
}
single email attachments
{
    attachments: [
        {
            filename: "fileName.extension",
            path: "./folderName/fileName.extension",
        }
    ]
}

multiple email attachments

{
    attachments: [
        {
            filename: "fileName.extension",
            path: "./folderName/fileName.extension",
        },
        {
            filename: "fileName.extension",
            path: "./folderName/fileName.extension",
        },
        {
            filename: "fileName.extension",
            path: "./folderName/fileName.extension",
        },
    ]
}

Version Support

  • node ^8.17.0 | ^19.1.0

Tech Stack

Dependencies:

  • nodemailer - sending mails
  • nodemailer-express-handlebars - .handlebars template
  • twilio - sending sms
  • dotenv - ready .env file

Features

email support

  • mailtrap
  • sendgrid
  • mailgun

sms support

  • twilio