Reputation: 380
THIS IS IN EXPRESS
I defined the variable
const username = "a"
const password = "a"
and then i redefined it with
{username, password} = req.body
(i had a form--this was /createaccount)
then, an error popped up which was unexpected token '=' is this because username is not defined in app.get(/createaccount...)
???
Upvotes: 0
Views: 41
Reputation: 647
Try below:
let username = "a";
let password = "b";
({username , password } = req.body);
Since you have declared username and password and used destructuring in the next line you need to wrap the destructuring inside ();
Quoting from https://developer.mozilla.org/:
The parentheses ( ... ) around the assignment statement are required when using object literal destructuring assignment without a declaration.
Upvotes: 1