NPM意外的令牌错误?

时间:2018-03-31 05:41:49

标签: node.js

当我尝试使用npm start运行我的项目时,我在控制台上收到以下错误,不知道原因。谁能解释我为什么?我忘记关闭代码中的任何内容了吗?除非这是与我使用的Vue js版本相关的问题?

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

当我使用linux运行它时,我没有任何问题,只会发生在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
          })

        }

      }

    })

0 个答案:

没有答案