语法错误:module.exports中的意外标识符

时间:2018-11-26 12:02:40

标签: javascript node.js

以下代码中导致错误的问题是什么? 在编写函数之前应该先写let还是function关键字?

module.exports = {
    postLogin=(req, res, next) => {
        const { mobile, password } = req.body;
        User.findByCredentials(mobile, password).then((user) => {
            return user.generateAuthToken().then((token) => {
                res.header('x-auth', token).send(user);
            });
        }).catch((e) => {
            res.status(400).send();
        });
    }
    getMe=(req, res, next) => {
        res.send(req.user);
    }
    getLogout=(req, res, next) => {
        req.user.removeToken(req.token).then(() => {
            res.status(200).send();
        }, () => {
            res.status(400).send();
        });
    }
}

1 个答案:

答案 0 :(得分:0)

正确的是:

module.exports = {
postLogin: (req, res, next) => {
    const { mobile, password } = req.body;
    User.findByCredentials(mobile, password).then((user) => {
        return user.generateAuthToken().then((token) => {
            res.header('x-auth', token).send(user);
        });
    }).catch((e) => {
        res.status(400).send();
    });
},
getMe: (req, res, next) => {
    res.send(req.user);
},
getLogout: (req, res, next) => {
    req.user.removeToken(req.token).then(() => {
        res.status(200).send();
    }, () => {
        res.status(400).send();
    });
} }