×
Home
Jobs
Tools
Coding Ground
Current Affairs
UPSC Notes
Online Tutors
Whiteboard
Net Meeting
Tutorix
Login
Packages
Categories
Java
JSP
iOS
HTML
Android
Python
C Programming
C++ Programming
C#
PHP
CSS
Javascript
jQuery
SAP
SAP HANA
Data Structure
RDBMS
MySQL
Mathematics
8085 Microprocessor
Operating System
Digital Electronics
Analysis of Algorithms
Mobile Development
Front End
Web Development
Selenium
MongoDB
Computer Network
General Topics
Library
Videos
Q/A
eBooks
Login
Library
Videos
eBooks
Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Selected Reading
UPSC IAS Exams Notes
Developer's Best Practices
Questions and Answers
Effective Resume Writing
HR Interview Questions
Computer Glossary
Who is Who
Shyam Hande
has Published
72
Answers
Styling html pages in Node.js
Node.js
Server Side Programming
Programming
Shyam Hande
Published on 13-May-2020 17:06:53
In html files we can simply add style in head section −<html> <head> <style> //add css code </style> </head> <body> </body> </html>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
Node.js
Server Side Programming
Programming
Shyam Hande
Published on 13-May-2020 17:04:18
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
Express JS
Server Side Programming
Programming
Shyam Hande
Published on 13-May-2020 17:01:42
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('<h1> Page not ...
Read More
Adding 404 page in express
Node.js
Server Side Programming
Programming
Shyam Hande
Published on 13-May-2020 16:58:57
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
Node.js
Server Side Programming
Programming
Shyam Hande
Published on 13-May-2020 16:56:34
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
Node.js
Server Side Programming
Programming
Shyam Hande
Published on 13-May-2020 16:54:12
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
Node.js
Server Side Programming
Programming
Shyam Hande
Published on 13-May-2020 16:52:03
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('<form action="/post-username" method="POST"> <input type="text" name="username"> <button type="submit"> Send </button> </form>'); });For parsing the http request, we requires a third party library body-parser: It’s a production required dependencynpm install ...
Read More
Handling different routes in express.js
Node.js
Server Side Programming
Programming
Shyam Hande
Published on 13-May-2020 16:49:50
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
Node.js
Server Side Programming
Programming
Shyam Hande
Published on 13-May-2020 16:11:03
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
What is express.js and installing it in Node.js?
Node.js
Server Side Programming
Programming
Shyam Hande
Published on 13-May-2020 16:08:06
Why requires express.js?Writing core node.js code to fetch request data and parsing it is complex enough. As we saw in previous posts, we wrote data and end event to get the simple request data.Express makes the process simpler. It helps developers to focus more on writing business logic instead of ...
Read More
1
2
3
4
5
6
7
8
Next
Advertisements
Print
Add Notes
Bookmark this page
Report Error
Suggestions
Save
Close
Dashboard
Logout