11

i try to read the user input and sent it as a email. but when i run this code it gives me this error: Assignment to constant variable.

Any help will be appreciate

var mail= require('./email.js')
var express = require('express')
var router = express.Router()

router.post('/',function(req, res, next){
    var address = req.fields.address
    var text = req.fields.text
    var subject = req.fields.subject

    try{
       if(text = 0){
           throw new Error('Please enter what u want to say')
       }
       if(subject = 0){
           throw new Error('Please enter subject')
       }

    }catch(e){
        req.flash('error', e.message)
        return res.redirect('back')
    }

    var detail = {
        to:address,
        text:text,
        subject:subject,
        from: 'test <nbuudilc@126.com>'
    }

    email(detail).then(function(){
        req.flash('success','email sent success')
        res.redirect('/posts')
    })

})

module.exports = router
Lee Cardo
  • 123
  • 1
  • 2
  • 8

1 Answers1

8

You might want:

if (text == 0)

and:

if (subject == 0)

or:

if (!text)

and:

if (!subject)

I would think the latter option is better, at least stylistically.