Mayank Agarwal has Published 373 Articles

Express.js – req.accepts() Method

Mayank Agarwal

Mayank Agarwal

Updated on 06-Apr-2022 07:38:54

952 Views

The req.accepts() method checks if the specified content-types are acceptable by the request's Accept HTTP header fields. This method returns the best match, and returns False if none of the specified content types is acceptable.The type values can be a MIME type like application/json, or an extension name like json.Syntaxreq.accepts( ... Read More

Express.js – express.urlencoded() Method

Mayank Agarwal

Mayank Agarwal

Updated on 06-Apr-2022 07:33:40

7K+ Views

express.urlencoded() is a built-in middleware in Express.js. The main objective of this method is to parse the incoming request with urlencoded payloads and is based upon the body-parser.This method returns the middleware that parses all the urlencoded bodies.Syntaxexpress.urlencoded( [options] )ParametersFollowing are the different options available with this method −options −inflate ... Read More

Creating a Simple Calculator using HTML, CSS, and JavaScript

Mayank Agarwal

Mayank Agarwal

Updated on 05-Apr-2022 07:10:33

4K+ Views

A Student grade calculator is used for taking the grades input for all subjects and then calculating the percentage based upon the marks of the students. This calculator returns a fairly reliable indicator of student results.The simple formula for calculating grades is:$\text{Percentage}=\frac{\text{Marks Scored}}{\text{Total Marks}}\times 100$We are going to take the ... Read More

Express.js – router.param() Method

Mayank Agarwal

Mayank Agarwal

Updated on 28-Mar-2022 14:50:39

1K+ Views

router.param(name, callback) adds a callback to the route parameters where name defines the name of the parameter and callback is the callback function.Following are the parameters of the callback function −req – the request objectres – the response objectnext -- the next middlewarename – value of the name parameterSyntaxrouter.param( name, callback ... Read More

Skipping middleware in Express.js

Mayank Agarwal

Mayank Agarwal

Updated on 28-Mar-2022 14:50:14

933 Views

You need to pass some parameters to skip the middleware in an Express application. On the basis of that parameter with logic in place, you can decide whether to execute a middleware or notSyntaxThere is no syntax defined. You can introduce a parameter and then check based upon that parameter ... Read More

Sending HTTP error code using Express.js

Mayank Agarwal

Mayank Agarwal

Updated on 28-Mar-2022 12:51:31

1K+ Views

We can send different HTTP status and responses over the Express.js app endpoint as per the user's requirement. Also we can send a message in case of an error or when the requests are forbidden. The status code 200 is sent by default with the response returned.Syntaxres.status( statusCode )Example 1Create ... Read More

Express.js – res.headersSent Property

Mayank Agarwal

Mayank Agarwal

Updated on 28-Mar-2022 12:46:46

1K+ Views

res.headersSent returns a Boolean value that indicates if the app has sent HTTP headers for the response or not. If the headers are sent, it returns True; else False.Syntaxres.headersSentExample 1Create a file with the name "headersSent.js" and copy the following code snippet. After creating the file, use the command "node ... Read More

Express.js – router.METHOD() Method

Mayank Agarwal

Mayank Agarwal

Updated on 28-Mar-2022 12:40:55

162 Views

The router.METHOD() is used for providing the method functionality in Express, where METHOD represents one of the HTTP methods such as GET, POST, PUT, and so on, in lowercase. Therefore, the actual methods are represented as following −router.get()router.post()router.put() …… and so on...Syntaxrouter.METHOD( path, [callback ...], callback )Example 1Create a file ... Read More

Express.js – res.get() Method

Mayank Agarwal

Mayank Agarwal

Updated on 28-Mar-2022 12:38:19

484 Views

The res.get() method is used to return the HTTP headers specified by the field. The match is case-insensitive and therefore returns all the matching patterns.Syntaxres.get( field )Example 1Create a file with the name "resGet.js" and copy the following code snippet. After creating the file, use the command "node resGet.js" to ... Read More

Express.js – req.range() Method

Mayank Agarwal

Mayank Agarwal

Updated on 28-Mar-2022 12:35:04

569 Views

req.range() is basically a range header parser. The accept-ranges and the response-header fields allow the server to indicate the acceptance of the range requests from a resource.Syntaxreq.range( size, [options])ParametersThe above parameters are defined as follows −size – The size parameter defines the maximum size of the resource.options – The options ... Read More

Advertisements