Adding Swagger To Existing Node.js Project

Adding Swagger To Existing Node.js Project

Today, almost every application has to be connected and to share data with other applications. The best way to do that is throughAPIs. For a long time there hasn’t been any industry standard for designing and documenting APIs. And API without a good documentation on how to use it, is useless. Because of that, developers have …

Make a mapping object from an array of objects using Reduce function in Javascript

Make a mapping object from an array of objects using Reduce function in Javascript

Sometimes, we face some usecases to make a mapping object from an array of object. For example, we have a Users array, we need to find a user by tagId. Here tagIdis supposed to be unique. Generally, we may try to use array.find() function to find the object with tagId. But using array.reduce()function in Javascript, …

Cancel Preceded Requests from Frontend side Using Axios

Cancel Preceded Requests from Frontend side Using Axios

There are some cases that user sends simultaneous requests while preceded requests are still pending. In this case, you will need to cancel the preceding requests. Axios provides cancelTokenfeature for this purpose. This stores cancelToken of previous request and use it to cancel the preceded requests with the token value.

Set or update field automatically without manual additional in Mongoose/MongoDB

Set or update field automatically without manual additional in Mongoose/MongoDB

I had a chance that I need to add new field for each schema in the MongoDB. First time, I thought I should add them manually for each model definition. I investigated a better way and found that MongoDB provides plugin feature and provides hooks for each Mongoose events like find, save, update, delete. For …

Get and set request-scoped context anywhere in Express app

Get and set request-scoped context anywhere in Express app

We may need to store user information to somewhere and want to grab the information from a utility function. Assuming I need to get current logged user and use it in mongoose schema functions. Using express-http-context npm package, you can easily implement this. In where you want to grab the information; If you want to …