0

When I try to run my project with npm start I'm getting the following error on the console, don't know why. Can anyone explain me why? Did I forget to close anything in the code? Unless this is an issue related to the Vue js version that I'm using?

D:\projects\vues\routes\user-routes.js:25
app.post('/user/signup', async (req, res) => {
                               ^
SyntaxError: Unexpected token (

I don't have any issue when i run it with linux, only happens with windows.

    app.post('/user/signup', async (req, res) => {
      let {
        body: { username, email, password, password_again },
        session
      } = req

      req.checkBody('username', 'Username is empty!!').notEmpty()
      req.checkBody('username', 'Username must contain only leters').isAlpha()
      req.checkBody('username', 'Username must be greater than 4').isLength({ min: 4 })
      req.checkBody('username', 'Username must be less than 32').isLength({ max: 32 })

      req.checkBody('email', 'Email is empty').notEmpty()
      req.checkBody('email', 'Email is invalid').isEmail()

      req.checkBody('password', 'Password field is empty').notEmpty()
      req.checkBody('password_again', 'Password field is empty').notEmpty()
      req.checkBody('password', 'Passwords don\'t match').equals(password_again)

      let errors = await req.getValidationResult()

      if (!errors.isEmpty()) {
        let array = []
        errors.array().forEach(e => array.push(e.msg) )
        res.json({ mssg: array })
      } else {

        let
          [{ usernameCount }] = await db.query('SELECT COUNT(username) as usernameCount from users WHERE username = ?', [username]),
          [{ emailCount }] = await db.query('SELECT COUNT(email) as emailCount from users WHERE email = ?', [email])

        if (usernameCount == 1){
          res.json({ mssg: 'Username already exists!!' })
        } else if (emailCount == 1){
          res.json({ mssg: 'Email already exists!!' })
        } else {

          let
            newUser = {
              username,
              email,
              password,
              joined: new Date().getTime()
            },
            { insertId } = await db.create_user(newUser),
            mkdir = promisify(fs.mkdir)

          await mkdir(dir + `/public/users/${insertId}`)
          fs
            .createReadStream(dir + '/public/images/spacecraft.jpg')
            .pipe(fs.createWriteStream(dir + `/public/users/${insertId}/avatar.jpg`))

          session.id = insertId
          session.username = username

          res.json({
            mssg: `Hello, ${username}!!`,
            success: true
          })

        }

      }

    })
Ru Chern Chong
  • 3,692
  • 13
  • 33
  • 43
Brian Millot
  • 179
  • 1
  • 12

0 Answers0