Sign in
Log inSign up

Should I use module.exports {} or class in JS

Imran Khan's photo
Imran Khan
·Sep 25, 2019

Hi ,

I need a recommendation of coding guide when it comes to controller method inside the node app. such as either to go with

module.exports = {

    index: async (req, res) => {
        try {
            const authors = await Author.find({}).sort({date: 1}).populate('tags', 'name -_id')
            return res.json(authors);     
        }
        catch (err) {
            console.error(err);
            res.status(500).send(err)
        }
    },

or

class UserController {

     static create_user(req, res)  {
               return res.json('test');
     }

}

Thank you guys.