Send ejs field to a nodejs file

154 views Asked by At

I have the following ejs code.

 <form action="/"  class = "form-horizontal" method="post">
 <textarea class = 'form-control departureCode' name = "departureCode"     rows= "1"></textarea>
 </form>

This is my post handler code in routes.js file.

routes.post('/', (req, res, next) => {
            let departureCode = JSON.parse(req.body.departureCode);
            console.log(departureCode);
        });

I m not getting this to work successfully. I am getting undefined token error inside my post handler. Could you please help me?

1

There are 1 answers

0
SamT On BEST ANSWER

removed JSON.Parse from

let departureCode = JSON.parse(req.body.departureCode);

It worked. Also, made changes suggested by Yogesh Patel in the comments. Thank you all.