Found 72 Articles for Express JS

How to Install & Setup MEAN Stack on Ubuntu (MongoDB, Express.JS, Angular.JS, Node.JS)

Satish Kumar
Updated on 28-Apr-2023 16:54:18

809 Views

The MEAN stack is a popular web development framework consisting of MongoDB, Express.js, Angular.js, and Node.js. It is an open-source platform that allows developers to create robust web applications quickly and efficiently. In this article, we will guide you through the installation and setup process of the MEAN stack on Ubuntu. Step 1: Install Node.js and NPM Node.js is the runtime environment that allows developers to run JavaScript code outside of the browser. It is the backbone of the MEAN stack. To install Node.js on Ubuntu, follow these steps − Open the terminal on Ubuntu by pressing Ctrl+Alt+T. Type the ... Read More

Node.js Alternatives

Shirjeel Yunus
Updated on 05-Apr-2023 16:45:38

204 Views

What is Node.js? Ryan Dahl developed Node.js in 2009 and its current version is v0.10.36. Node.js is a server-side platform which is developed on the JavaScript Engine of Google Chrome. This is a cross-platform runtime environment which can be used to develop server-side and networking applications. JavaScript is used to create Node.js applications which can be executed on Node.js environment installed on various platforms like OSX, Linux, and Windows. Cost of Node.js Node.js is an open-source library and can be used for free. There are many hosting platforms that utilize Node.js. Some of them provide paid services. Why Node.js Alternatives? ... Read More

Express.js – req.subdomains Property

Mayank Agarwal
Updated on 06-Apr-2022 08:27:37

363 Views

req.subdomains returns an array of all the subdomains in the domain name of the request. The application property subdomain offset is used for determining the beginning of the subdomain segments. The default value of the subdomain offset property is 2.Syntaxreq.subdomainsExampleCreate a file with the name "reqSubdomains.js" and copy the following code snippet. After creating the file, use the command "node reqSubdomains.js" to run this code as shown in the example below −// req.subdomains Property Demo Example // Importing the express var express = require('express'); // Initializing the express and port number var app = express(); // Initializing the ... Read More

Express.js – req.signedCookies Property

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

210 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 to "{ }", if no cookies are sent.Syntaxreq.signedCookiesInstalling the cookie-parser modulenpm install cookie-parserExample 1Create a file with the name "reqSignedCookies.js" and copy the following code snippet. After creating the file, use the command "node reqSignedCookies.js" to run this code as shown in the example below −// req.signedCookies() Method Demo Example ... Read More

Express.js – req.originalUrl Property

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

595 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 name "reqOriginalUrl.js" and copy the following code snippet. After creating the file, use the command "node reqOriginalUrl.js" to run this code as shown in the example below −// req.originalUrl Property Demo Example // Importing the express var express = require('express'); // Initializing the express and port number var app ... Read More

Express.js – req.ips Property

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

219 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 with the name "reqIps.js" and copy the following code snippet. After creating the file, use the command "node reqIps.js" to run this code as shown in the example below −// req.ips Property Demo Example // Importing the express & cookieParser module var cookieParser = require('cookie-parser'); var express = require('express'); ... Read More

Express.js – req.ip Property

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

1K+ 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 with the name "reqIp.js" and copy the following code snippet. After creating the file, use the command "node reqIp.js" to run this code as shown in the example below −// req.ip Property Demo Example // Importing the express & cookieParser module var cookieParser = require('cookie-parser'); var express = require('express'); ... Read More

Express.js – req.baseUrl Property

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

1K+ 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 creating the file, use the command "node reqBaseUrl.js" to run this code as shown in the example below −// req.baseUrl Property Demo Example // Importing the express var express = require('express'); // Initializing the express and port number var app = express(); // Initializing the router from express ... Read More

Express.js – res.end() Method

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

3K+ 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 copy the following code snippet. After creating the file, use the command "node resend.js" to run this code as shown in the example below −// res.end() Method Demo Example // Importing the express module var express = require('express'); // Initializing the express and port number var app = express(); ... Read More

Generating Random Short Id in Node.js

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

886 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 without duplication.SyntaxSetting up the NPM project:npm init -yInstalling the 'shortId' dependency:npm install express shortidImporting shortId:const short = require('shortid');Example 1Create a file with the name "shortId.js" and copy the following code snippet. After creating the file, use the command "node shortId.js" to run this code as shown in the example below ... Read More

1 2 3 4 5 ... 8 Next
Advertisements