1.0.11 • Published 2 years ago

@zurckz/nodejs-ms-core v1.0.11

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

z-nodejs-ms-core

Core layer for fast and productive building of microservices using TypeScript, express and AWS Cloud.

Getting Started

Modules

Demo

WS Deployed in AWS Lambda

User Controller

user.controller.ts

export const PostController = async (req: Request, res: Response) => {
  try {
    containsParams(req.params, "userId");
    ok(req, res, { name: "Zurckz" });
  } catch (e) {
    error(req, res, e);
  }
};

App.ts

/**
 * Create an instance of Express Application
 */
const app = new EApp();

/**
 * Setup Application 🛠
 */
app.setup(
  getEnvOr("LOCAL_PORT", "5000"),
  (_) => {
    app.configureMiddleware({
      consumer: (e) => e.use(awsMiddleware.eventContext()),
      enabled: true,
      name: "aws",
    });
    app.GET({
      path: "/users/:userId",
      handler: UserController,
    });
  },
  (_) => NeoDB.init()
);

/**
 *  Start server 🚀, if the current environment is local 🏡
 * otherwise export app.
 */
if (getEnv("env") == "local") app.start();
else module.exports = app.express;

Lambda Hanlder

handler.js

const aws = require("aws-serverless-express");
const app = require("./index");
const server = aws.createServer(app);

exports.handler = (e, c) => aws.proxy(server, e, c);

Demo SQS

Hanlde SQS Event

App.ts

/**
 * Create an instance of Express Application
 */
const sqs = new SQSApp(() => NeoDB.init());

/**
 * Setup Application 🛠
 */
sqs.onRecords = async (records: SQSRecord[]) => {
  for (const record of records) {
    await doSomeThing(record);
  }
  return true;
};

/**
 *  Run test 🚀, if the current environment is local 🏡
 * otherwise export app.
 */
if (getEnv("env") == "local")
  sqs.test(__dirname.replace("dist", "SQSEvent.json"));
else module.exports = sqs;

Lambda Hanlder

handler.js

const zk = require("@zurckz/nodejs-ms-core");
const app = require("./index");

exports.handler = async (e, _) => await zk.SQSApp.proxy(app, e);

Prerequisites

  • NodeJS 14

Dependencies

  • neo4j-driver
  • tslog
  • express

Installing

Install package

npm i @zurckz/nodejs-ms-core

Built With

  • npm - Dependency Management

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository .

Authors

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

3 years ago