[root@fh comm-node]# node app.js
/root/comm-node/node_modules/express-validator/src/middlewares/one-of.js:7
return async (req, _res, next) => {
^
SyntaxError: Unexpected token (
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at Object.Module._extensions…js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (/root/comm-node/node_modules/express-validator/src/index.js:6:10)
at Module._compile (module.js:570:32)
我的router/user.js代码如下
const express = require('express')
const Result = require('../models/Result')
const { login } = require('../services/user')
const { md5 } = require('../utils')
const { PWD_SALT } = require('../utils/constant')
const { body, validationResult } = require('express-validator')
const boom = require('boom')
const router = express.Router()
// 嵌套路由
router.post(
'/login',
[
body('username').isEmail().withMessage('username类型不正确'),
body('password').isLength({ min: 6 }).withMessage('password类型不正确')
],
(req, res, next) => {
const err = validationResult(req)
if (!err.isEmpty()) {
const [{ msg }] = err.errors
next(boom.badRequest(msg))
} else {
const username = req.body.username
const password = md5(`${req.body.password}${PWD_SALT}`)
login(username, password).then(user => {
if (!user || user.length === 0) {
new Result('登录失败').fail(res)
} else {
new Result('登录成功').success(res)
}
})
}
})
router.get('/info', function (req, res, next) {
res.json('user info...')
})
module.exports = router
基于Element的中后台课程,一套中小型企业通用的后台管理系统
了解课程