Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
Display message using express

I need to display an alert message in browser using Node.js code but its not working. I need to display a message saying that empty field! or success!. Here my code

const flash = require('express-flash')
const session = require('express-session')

app.use(session({
    saveUninitialized: false,
    resave: false,
    secret: 'ujnersqkbpmas'
}))
app.use(flash());

app.post('/products/create', (req,res) => {
    upload(req, res, (err) => {
        const name = req.body.name
        const description = req.body.description
        const Filename = req.file.filename
        if(!name || !description){ 
             req.flash('msg', 'empty field!');
        }
        else{
            db.uploadPost(name, description, Filename, function(error, id){
                if(error){
                    console.log(err)
                }
                else{
                    req.flash('msg', 'success!');
                    res.redirect('/products/'+id)
                }
            })
        }
    })
})

html code

<div>
    {{#if messages.msg}}
        <p>{{messages.msg}}</p>
    {{/if}}
</div>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!