Posts for Deven

Deven is an Entrepreneur, and Full-stack developer, Constantly learning and experiencing new things. He currently runs CodeSource.io and Dunebook.com
Deven
Deven wrote

Express res.json() example

Once the server process the client request, the result needs to be sent back to the client. Express provides various methods to send the result like res.send(), res.json(), res.redirect(). In today’s post, we are going to see res.json(). res.json() is a utility wrapper around res.send() that also adds the Content-Type: application/json header to the response. This header […]

October 19, 2021 in Code examples
Deven
Deven wrote

Express Router params example

REST APIs support multiple parameter types like: Header, Query String, Path & Request body. Routing refers to how an application’s endpoints (URIs) respond to client requests. Here, we will cover how can your server access path or route parameters. These parameters are a part of the url itself eg. GET /client/93 Express Router params Express Router parameters are specific attributes […]

October 19, 2021 in Code examples
Deven
Deven wrote

JavaScript Add to List : examples

An array is a single variable in JavaScript which holds multiple elements inside it. Each element inside the array has a unique index assigned to it. You can access the element inside the array using that index. Array can be changed or mutated with many built in methods. Let’s cover some methods to add new […]

October 19, 2021 in Code examples
Deven
Deven wrote

AJAX Post request example

There are various HTTP methods available to access data or send data to the server. HTTP provides get, post, put, patch, delete methods. In today’s post we are going to use Post method with the help of AJAX. AJAX stands for Asynchronous JavaScript And XML, which allows the webpage to be updated in the backgroud […]

October 19, 2021 in Code examples
Deven
Deven wrote

How to use Populate in mongoose

In this article, you will learn about the mongoose populate. From version 3.2 or above, MongoDB has the join, like $lookup aggregation operator. But in mongoose, you will get a more powerful alternative which name is populate(). It will let you reference documents in other collections. In mongoose, Populate is the way of replacing a […]

October 18, 2021 in Code examples
Deven
Deven wrote

How to use eslintignore

In this article, you are going to know about eslintignore.ESLint is a tool that inspects your ECMAScript/JavaScript code and points out issues based on some pre-defined rules. It focused on make the code more consistent and avoid unwanted bugs. Sometimes you need to ignore a file. If you want a particular file not to be […]

October 18, 2021 in Code examples
Deven
Deven wrote

How to use findOneAndUpdate in mongoose

In this article, you will learn about how to use Mongoose findOneAndUpdate In Mongoose there are many effective methods for updating data. Each method is designed for a single purpose but they work differently. One of these methods is findOneAndUpdate(). Mongoose’s findOneAndUpdate() function finds the first document that matches a given filter, then applies an […]

October 18, 2021 in Code examples
Deven
Deven wrote

How to use chai assertion library

In this article, you will learn about how to use the Chai assertion library.Assertion libraries are tools to verify that things are correct. Basically, It helps you to test your code and reduce your time by preventing writing thousands of if statements. Chai is an assertion library. More specifically, Chai is a BDD / TDD […]

October 18, 2021 in Code examples & Javascript
Deven
Deven wrote

Learn How to use Mongoose timestamps

In this article, You will learn how to use Mongoose timestamps. Mongoose schemas have a timestamps option that informs Mongoose to automatically manage createdAt and updatedAt properties on your documents. Everything in Mongoose starts with a Schema. MongoDB collection maps each schema and within that collection, it defines the shape of the documents. Let’s assume […]

October 16, 2021 in Code examples
Deven
Deven wrote

Learn How to use Mongoose aggregation

In this article, you are going to learn about Mongoose aggregation. In MongoDB, the aggregation pipeline consists of stages and each stage transforms the document. It is extremely powerful and very handy to use. Mongoose comes with aggregate() function by which you can use MongoDB’s aggregation framework with Mongoose. Basically, it is a thin wrapper […]

October 16, 2021 in Code examples
Deven
Deven wrote

How to use Mongoose findOneAndUpdate

Mongoose provides various methods to update the document like .save(), findOneAndUpdate(), updateOne(). In today’s post we are going to use findOneAndUpdate(). findOneAndUpdate(): There are multiple documents saved inside mongoDB which match the criteria of update condition. findOneAndUpdate method matches the first document that satisfies the condition & updates it. By default, findOneAndUpdate() returns the original […]

October 15, 2021 in Code examples
Deven
Deven wrote

How to use Promise.then() in JavaScript

The then() method returns a Promise. It takes up to two arguments: callback functions for the success and failure cases of the Promise. Promises can be chained one after the other using the .then() chain. The subsequent promises in .then chain are only executed once the current promise resolves successfully. If the current promise rejects […]

October 15, 2021 in Code examples
Deven
Deven wrote

How to use Promise.reject() in JavaScript

In JavaScript,  Promises are used to denote an ongoing task which has not completed yet. It may Resolve with a result or Reject with an error. It can take an infinite amount of time to complete something internally. A promise may have more promises within it. Promises can be chained one after the another to […]

October 15, 2021 in Code examples
Deven
Deven wrote

How to use findById in Mongoose

Each document inside MongoDB has a unique id associated with it, which helps to identify the document independently. It is similar to primary key defined in MySQL. findById: This method takes Id as input parameter & returns the single matching document. FindById is shortcut of findOne({ _id: id }) example: Once a user hits this […]

October 15, 2021 in Code examples
Deven
Deven wrote

How to get all documents in Mongoose

In this article, You will learn how to get all documents in Mongoose. Let assume, you have a mongoose model User that has all your app’s users information. Now, to get all users list from the mongoose collection you have to call User.find() with an empty object as the first parameter. It will search for […]

October 15, 2021 in Code examples