Mayank Agarwal has Published 373 Articles

Express.js – req.signedCookies Property

Mayank Agarwal

Mayank Agarwal

Updated on 06-Apr-2022 08:26:34

315 Views

req.signedCookies contains the signed cookies (ready for use) sent by the request while using the cookie-parser middleware. Signed cookies exist in a different object to show the developer intent, else a malicious attack could be made on the request.cookie values that are relatively easy to spoof.The property defaults are set ... Read More

Express.js – req.originalUrl Property

Mayank Agarwal

Mayank Agarwal

Updated on 06-Apr-2022 08:23:37

1K+ Views

The req.originalUrl property is similar to the req.url property. This property retains the original URL and lets us rewrite the same to redirect the request further to some other network or as needed. The app.use() method will rewrite the req.url to strip the mount point.Syntaxreq.originalUrlExample 1Create a file with the ... Read More

Express.js – req.ips Property

Mayank Agarwal

Mayank Agarwal

Updated on 06-Apr-2022 08:21:30

334 Views

The req.ips property contains an array of all the IP addresses in the X-Forwarded-For request header value. This property is only populated when the trust proxy setting does not evaluate to False. This header values or IP's can be set either by the proxy or the client.Syntaxreq.ipsExample 1Create a file ... Read More

Express.js – req.ip Property

Mayank Agarwal

Mayank Agarwal

Updated on 06-Apr-2022 08:17:07

2K+ Views

req.ip consists of the remote IP address from where the request is received. The value of this property is taken from the leftmost entry in the x-forwarded-for header when the trust proxy settings are not set to False. The headers are set by the client or proxy.Syntaxreq.ipExample 1Create a file ... Read More

Express.js – req.baseUrl Property

Mayank Agarwal

Mayank Agarwal

Updated on 06-Apr-2022 08:13:49

2K+ Views

The req.baseUrl property returns the router instance where this URL path is mounted. This property is similar to the mountpath property of the app object, except for the difference that app.mountpath returns the matched path patterns.Syntaxreq.baseUrlExample 1Create a file with the name "reqBaseUrl.js" and copy the following code snippet. After ... Read More

Express.js – res.end() Method

Mayank Agarwal

Mayank Agarwal

Updated on 06-Apr-2022 08:09:42

4K+ Views

The res.end() method ends the current response process. This method is used to quickly end the response without any data. If one needs to respond with data, they should use either the res.send() method or the res.json() method.Syntaxres.end([data], [encoding])Default encoding is 'utf-8'.Example 1Create a file with the name "resEnd.js" and ... Read More

Generating Random Short Id in Node.js

Mayank Agarwal

Mayank Agarwal

Updated on 06-Apr-2022 08:07:04

1K+ Views

The 'shortId' package from NPM can be used to create short non-sequential URL-friendly unique ID's. By default, it returns a 7-14 URL-friendly characters from the following categories: "A-Z, a-z, 0-9, _, -". This package also supports clusters (automatically), custom seeds, and custom alphabets. It can generate any number of ID's ... Read More

Getting Query String Variables in Express.js

Mayank Agarwal

Mayank Agarwal

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

10K+ Views

In Express.js, you can directly use the req.query() method to access the string variables. As per the documentation, the req.param method only gets the route parameters, whereas the req.query method checks the query string parameters. For example, "?id=12" checks urlencoded body params.Syntaxreq.query( )Example 1Create a file with the name "reqQuery.js" ... Read More

Express.js – req.acceptsLanguage() Method

Mayank Agarwal

Mayank Agarwal

Updated on 06-Apr-2022 07:49:47

606 Views

The req.acceptsLanguage() method returns the first accepted language out of the specified languages based on the request's Accept-Language HTTP header field. This method returns 'false' if none of the specified language is accepted.Syntaxreq.acceptsLanguage ( lang, [...] )Example 1Create a file with the name "reqLang.js" and copy the following code snippet. ... Read More

Express.js – req.acceptsCharsets() Method

Mayank Agarwal

Mayank Agarwal

Updated on 06-Apr-2022 07:43:35

213 Views

The req.acceptsCharsets() method returns the first accepted charset of the specified charset sets. These charsets are based on the request's Accept-Charset HTTP header field. By default, it returns 'false' if none of the specified charsets is accepted.Syntaxreq.acceptsCharsets ( charset, [...] )Example 1Create a file with the name "reqAcceptsCharsets.js" and copy ... Read More

Previous 1 ... 7 8 9 10 11 ... 38 Next
Advertisements