npm install --save ../common-module
Examples util
import { isEmptyObject } from "common-module/util";
console.log(isEmptyObject({}));
logger
import { Logger } from "common-module/util/logger";
Logger.info("This is my info", null, true);
bcrypt
import { Bcrypt } from "common-module/util/bcrypt";
console.log(Bcrypt.createHash("sanjay"));
jwt
import { Jwt } from "common-module/util/jwt";
console.log(Jwt.createToken({ id: 11 }));
crypto
import { Crypto } from "common-module/util/crypto";
const d1 = Crypto.encrypt("sanjay");
console.log(d1);
const d2 = Crypto.decrypt(d1);
console.log(d2);
email
import { sendMail, MailArg } from "common-module/util/mail";
let mailData = new MailArg(
"sanjay.mscit7@gmail.com",
"Test mail",
"test by sanjay"
);
sendMail(mailData, function (error, info) {
if (error) {
console.error(error);
}
if (info)
console.log("Mail email sent successfully, messageId => ", info.messageId);
});
push notification
import {
DeviceType,
NotificationBodyArg,
sendPushNotification,
} from "common-module/util/notification";
let notificationData = new NotificationBodyArg(
"Test notification",
"test by sanjay",
1,
"profile",
{ name: "sanjay" },
2
);
sendPushNotification(
"qwertyuiopasdfghjklzxcvbnm",
DeviceType.IOS,
notificationData,
function (error, info) {
if (error) {
console.error(error);
}
if (info) {
console.log("Notification sent successfully, messageId => ");
console.log(info);
}
}
);
sms
import { sendSms } from "common-module/util/sms";
sendSms("+917778899848", "this is test", function (error, info) {
if (error) {
console.log("error => ", error);
}
if (info) {
console.log("info => ", info);
}
});
Examples middleware
import apiAuthMiddleware from "common-module/middleware/api-auth";
import decryptRequestMiddleware from "common-module/middleware/decrypt-request";
import encryptResponseMiddleware from "common-module/middleware/encrypt-response";
app.use(apiAuthMiddleware);
app.use(encryptResponseMiddleware);
app.use(decryptRequestMiddleware);
Examples Handler
error handling
import {encryptErrorHandler,errorHandler,InternalServerError} from "common-module/handler/error-handler";
Example Response
http response
import {HttpResponse} from "common-module/response/http-response";
encrypt http response
import { EncryptHttpResponse } from "common-module/response/encrypt-http-response";