Shyam Hande has Published 72 Articles

Standalone React.js basic example

Shyam Hande

Shyam Hande

Updated on 03-Jul-2020 09:02:34

Lets first start with writing a simple HTML code and see how we can use ReactBasic React example  − Create a simple div like below −    Steve    My hobby: Cricket Add some styling elements.player{    border:1px solid #eee;    width:200px;    box-shadow:0 2px 2px #ccc;    padding: 22px; ... Read More

Styling html pages in Node.js

Shyam Hande

Shyam Hande

Updated on 13-May-2020 13:37:19

In html files we can simply add style in head section −                    //add css code           We can add inline css styles as well in html directly.Generally css is separated from the html ... Read More

Serving html pages from node.js

Shyam Hande

Shyam Hande

Updated on 13-May-2020 13:34:35

So far we sent html code directly from the send(0 function in response object. For sending larger code, we definitely require to have a separate file for html code.sendFile() function−Response object gives a sendFile() function to return a html file to client.How to provide path to html file in sendFile() ... Read More

Filtering paths and creating html page in express.js

Shyam Hande

Shyam Hande

Updated on 13-May-2020 13:32:50

We added express router to handle routes. One single router file handles multiple routes.Adding a path for router in App.js −const http = require('http'); const express = require('express'); const bodyParser = require('body-parser'); const route = require('./routes'); const app = express(); app.use(bodyParser.urlencoded({extended: false})); app.use('/test', route); app.use((req, res, next)=>{    res.status(404).send(' Page not ... Read More

Adding 404 page in express

Shyam Hande

Shyam Hande

Updated on 13-May-2020 13:29:27

Now we have a App.js and route.js for handling routes. For any other http requests for which we have not added any request handling will results into an error page. Example for url ‘test’ −App.jsconst http = require('http'); const express = require('express'); const bodyParser = require('body-parser'); const route = ... Read More

How to use express router

Shyam Hande

Shyam Hande

Updated on 13-May-2020 13:27:17

In earlier examples, we wrote all routing code in a single file App.js. But in real world scenarios, we have to split the code into multiple files.We can create separate files and import them but express gives a router mechanism which is easy to use.Create a separate file called route.js ... Read More

Using post request in middleware in express

Shyam Hande

Shyam Hande

Updated on 13-May-2020 13:25:04

We used use() function to execute middleware’s . Example we used below will be executed for both http GET and POST method −const http = require('http'); const express = require('express'); const bodyParser = require('body-parser'); const app = express(); app.use(bodyParser.urlencoded({extended: false})); app.use('/', (req, res, next)=>{    next(); }); app.use('/add-username', (req, res, ... Read More

Parsing incoming requests in express.js

Shyam Hande

Shyam Hande

Updated on 13-May-2020 13:22:29

To receive some data in http request , lets add a form on url path ‘/add-username’:app.use('/add-username', (req, res, next)=>{    res.send(' Send '); });For parsing the http request, we requires a third party library body-parser: It’s a production required dependencynpm install –save body-parserexpress js provides middleware use ... Read More

Handling different routes in express.js

Shyam Hande

Shyam Hande

Updated on 13-May-2020 13:20:49

For handling different routes, use() function is used. use() function has multiple overloaded version, one of version also takes url path as a argument. Based on the url path, the requests will be filtered out for respective middleware.const http = require('http'); const express = require('express'); const app = express(); app.use('/', ... Read More

Adding middleware in Express in Node.js

Shyam Hande

Shyam Hande

Updated on 13-May-2020 12:42:00

Each request in app goes through multiple middleware’s in express. If one of the middleware returns the response it ends there. If any middleware wants to pass the request to next middleware, it uses next() function call at the end of its function call.Http Request -> Middleware (req, resp, next)-> ... Read More

1 2 3 4 5 6 7 8 Next
Advertisements