Mayank Agarwal has Published 380 Articles

Express.js – app.set() Method

Mayank Agarwal

Mayank Agarwal

Updated on 30-Sep-2021 14:28:38

3K+ Views

The app.set() function assigns or sets a setting name to value. This can store any type of value as the user wants, but there are some certain names that can be used to configure the behaviour of the serverSome of the properties that can be configured with the set functionality ... Read More

Express.js – app.route() Method

Mayank Agarwal

Mayank Agarwal

Updated on 30-Sep-2021 14:18:50

930 Views

The app.route() method returns the instance of a single route. This single route can be used to handle the HTTP verbs with the optional middleware. This method is mainly used to avoid duplicate names.Syntaxapp.route( )Example 1Create a file with the name "appRoute.js" and copy the following code snippet. After creating ... Read More

Express.js – app.render() Method

Mayank Agarwal

Mayank Agarwal

Updated on 30-Sep-2021 14:04:25

2K+ Views

The app.render() method is used for returning the rendered HTML of a view using the callback function. This method accepts an optional parameter that is an object which contains the local variables for the view.This method is similar to the res.render() function with the difference that it cannot send the ... Read More

Express.js – app.post() Method

Mayank Agarwal

Mayank Agarwal

Updated on 30-Sep-2021 13:59:08

7K+ Views

The app.post() method routes all the HTTP POST requests to the specified path with the specified callback functions.Syntaxapp.path(path, callback, [callback])Parameterspath − This is the path for which the middleware function is invoked. A path can be a string, path pattern, a regular expression or an array of all these.callback − ... Read More

Express.js – app.path() Method

Mayank Agarwal

Mayank Agarwal

Updated on 30-Sep-2021 13:55:55

525 Views

The app.path() method returns the canonical path. The path is returned as a string. It is better to use the req.baseUrl method since the app.path() method can be very complicated in complex cases of mounted apps.Syntaxapp.path( )Example 1Create a file with the name "appPath.js" and copy the following code snippet. ... Read More

Express.js – app.param() Method

Mayank Agarwal

Mayank Agarwal

Updated on 30-Sep-2021 13:51:22

832 Views

The app.param() method is basically used for adding the callback triggers to the route parameters, where name represents the name of the parameter or an array of them and callback represents the callback function.Syntaxapp.param([name], callback)Parametersname − Represents the name of the parameter or array of parameters as required.callback − Represents ... Read More

Express.js – app.mountpath Property

Mayank Agarwal

Mayank Agarwal

Updated on 30-Sep-2021 13:45:15

355 Views

The app.mountpath property contains those path patterns on which a sub-app was mounted. A sub-app can be defined as an instance of Express that may be used for handling the request to a route.This property is similar to the baseUrl property of the req object; the only difference is that ... Read More

Express.js – app.locals Property

Mayank Agarwal

Mayank Agarwal

Updated on 30-Sep-2021 13:35:14

951 Views

The app.locals object defines the properties that are local variables inside an application. Once the value of app.locals property is set, it persists throughout the life of the application. The res.locals property is valid only for the lifetime of the request.Syntaxapp.localsExample 1Create a file "appLocals.js" and copy the following code ... Read More

Express.js – app.listen() Method

Mayank Agarwal

Mayank Agarwal

Updated on 30-Sep-2021 13:29:13

7K+ Views

The app.listen() method binds itself with the specified host and port to bind and listen for any connections. If the port is not defined or 0, an arbitrary unused port will be assigned by the operating system that is mainly used for automated tasks like testing, etc.The app object returned ... Read More

Express.js – app.engine() Method

Mayank Agarwal

Mayank Agarwal

Updated on 30-Sep-2021 12:37:41

516 Views

The app.engine() method is used for registering the given template engine callback as "ext". The require() method needs the engine based on the function by default.Use the following methods for engines that do not provide the extensions (or want to map different extensions) or express out of the box.app.engine('html', require('ejs').renderFile)Syntaxapp.engine(ext, ... Read More

Advertisements