Node.js

10 Tips for using Semantic Release

1. Make sure to have the correct name value for the module in package.json. Include a prefix if it is necessary like this, “name”: “@mdhnpm/react-cube-loading-spinner” 2. Make sure to add publishConfig in package.json “publishConfig”: { “registry”: “https://registry.npmjs.org/” }, 3. Do not set “private”: true if you want to publish the …

Node.js

Data Provider Pattern with Jest

Jest has the for method that enables us to do a data provider pattern. for works on both describe and it. It is better to use it in describe so that the assertion messages in it can be dynamically generated.

Node.js

How to Avoid Async Try-Catch Hell

This post is based on this excellent short youtube video.. Let’s see async try-catch hell. If we do try-catch on every single async function, it creates a tower of terror. Welcome to try-catch hell. async function towerOfTerror() { let a; let b; let c; try { a = await step1(); …

Node.js

TyoeORM vs Prisma to build GraphQL APIs with TypeScript

If you are building GraphQL APIs with TypeScript and have a relational database, there are two main ORM libraries we can use: Prisma and TypeORM. Both of them are similar. They both use models to define database tables, have query APIs, handle db connection well, have good documentations and community …

Node.js

Handling Authorisation With Apollo

There are many ways to handle authorisation with Apollo. Authorisation is the process to determine if the authenticated user has access rights for the particular resources while authentication is to confirm the user’s identity. In short, my recommendation is (5), by using graphql-shield. You can also check the code example …

Node.js

Node.js Libraries for Protecting GraphQL APIs

If you want to look beyond authentication and authorisation to protect your GraphQL APIs, there are a few Node.js libraries you can have a look at. 1. Implementing Rate-Limiting Protection Rate-limiting will prevent too many requests coming in at once. For this, you can start with looking at graphql-rate-limit-directive. It …

Node.js

How to fix the error: “Cannot use GraphQLSchema “[object GraphQLSchema]” from another module or realm.”

When I created a lambda function with Typescript and GraphQL support with the apollo-server-lambda module (see the repo here), I got the error. It took me a while to figure out how to fix it, but finally I did by adding a module to webpack. The solution for this issue …

Node.js

JavaScript Workout

I made a JavaScript workout with a md file in my GitHub repo. Check out the work out here. The idea of this is to list a short JavaScript programming questions that you would encounter every day as a JavaScript developer. If you know how to do these, you don’t …

Node.js

Node Module to Retrieve Multiple Parameters from AWS Parameter Store

I created a node module to retrieve multiple parameters as the parameterName-parameterValue Json object from AWS Parameter Store. It is called aws-ssm-parameters and is available from Npm. The module is namespaced. So, you need to add the namespace @mdhnpm when you install it. npm i @mdhnpm/aws-ssm-parameters The main motivation for creating …

Node.js

AWS Lamda Function TypeScript Boilerplate

I have created a boilerplate for TypeScript lambda function. If you are into JavaScript, I have the boilerplate here. TypeScript is really JavaScript that scales as the official tag line suggests. It is type-safe and the TypeScript specific intellisense provided by Visual Code Studio is amazing. Compared to writing in …