Node JS Tutorial | Display Flash Messages using Connect-flash Module

In Web Development


Node JS Tutorial | Display Flash Messages using Connect-flash Module - read the full article about Angular Js update, Web Development and from Webslesson on Qualified.One
alt
Webslesson
Youtube Blogger
alt

hello friends in this video tutorial we will show you how to display flash messages on the web page in node.js by using connectflash module of nodejs this flash message has been displayed only one time when page has been redirect and when we have to refresh web page flash message will be removed and flash message has been used for display any success event any validation error or display any information so now we will display flash message under our node jstrud application so when we have to insert or update or delete operation then that operation success message will be displayed using this flash message now lets start discussing this topic so for display flash message first we need to install express session and connect flash module under our node application so for this we have go to command prompt [Music] and here we have go into our node express application directory and here we have to run following command this command will download connect flash and expression session module under our node application so here we can see that here we have write express which is required by the connectflash library to run and here we have using express session module so it will create session whenever a message is flashed and it will display message on next redirected web page now we want to integrate flash message in our node application so here in text editor we have to open app.js file and under this file we need to import connect flash and express session module so here first we need to import express session module so for this here we have to write session variable is equal to [Music] require function and under this we have to write express session module name after this we need to include connect flash module so here we have to write flash variable is equal to require function and under this we have to write connect flash module name so this way we can import modules under app.js file now we need to implement flash message under app.js file so here we have to write app.use function and under this function we have to write session function so this function will set up session in the node application under this function we have to write first parameter secret with value webs lesson it is a random unique string key which is used to authenticate a session after this we have write cookie parameter with value max 8 set to 60 000 this option sets the cookie expiry time and he browser will delete the cookie after the set duration elapses in third option we have to write say when initialized which is set to false and in last option we have to write resave option which is set to false so this way we can setup session in node application now we want to call connect flash module so for this here we have to write app.use function and under this function we have called flash function which well call connect flash module [Music] now we have go to roots directory and here we have to open sampledata.js file and under this file first we want to display success message when data has been inserted [Music] so for this we have go to insert data root and here above web page redirect code we need to define flash message code so for this here we have to write request dot flash function [Music] with two parameter so here in first parameter we have to write success and in second parameter we have to write message so here in message we have to write sample data inserted so after successfully inserting of data it will display success on web page on next web page redirect after this we want to display flash message on edit event so we have go to edit form submit root and here we have to write request dot flash function with two parameter so here in first parameter we have to write success and in second parameter we have to write sample data updated message so it will display the splash message after successfully editing of data and after this we want to display flash message on delete data operation so for this we have go to delete data root and here we have to write request dot flash function with two parameter in first parameter we have to write success and in second parameter we have to write sample data deleted message so it will display this flash message after successfully deleting of mysql data after this for display flash message on the web page so we have go to view directory and here we have to open sampledata.a.js template file and on the file we have go into display mysql data in html block of code [Music] and here first we have to write node code syntax and between this we have to write if statement and under condition we have to write message dot length value is greater than zero if this condition true that means there is any flash message has been stored under session [Music] and it will execute if block of code and under this block we have to create one division tag with class is equal to bootstrap alert and alert success class and between this we need to display flash message so here we have to write node code syntax and for print data on web page here we have to write is equal to sign and after this we have to write message variable which will print flash message on the web page so here our code is ready now we have save it and go to command prompt and here we have to run this command so this command will start node.js server now in the browser we have type localhost with 3000 port number sample data so here on web page we can see that mysql table data has been displayed in html table format [Music] now we have to click on the add button [Music] so here we can see that add data form has been load in browser now here we have to fill form details one by one [Music] and after this we have to click on the add button so after click on the add button here we can see that web page has been redirect and here we can see that mysql data has been displayed on web page and above this we can see flash message like data insert now we want to display flash message on edit data event so we have to click on this row edit button so here we can see that edit form has been loaded in browser with fill form data now we have make some changes in form data and after this click on the edit button so after click on the edit button here page has been redirect to another page and here we can see mysql data in html table format and above it we can see flash message which has been display after edit data event and lastly we want to display flash message on delete data event so for this we have click on this row delete button and after click on the delete button here can see that data has been deleted and here we can see flash message on delete data event so this way we can display flash message in node js using connect flash module and here we have completed node.js crud application in next part we will be meet with some interesting video tutorial so we will be meet in the next part lastly thank you for watching this tutorial and do not forget to subscribe our channel

Webslesson: Node JS Tutorial | Display Flash Messages using Connect-flash Module - Web Development