// routes/auth
router.get("/profile/:userId", auth.publicProfile);

// controllers/auth
export const publicProfile = async (req, res) => {
  try {
    const user = await User.findById(req.params.userId);
    user.password = undefined;
    user.resetCode = undefined;
    res.json(user);
  } catch (err) {
    console.log(err);
    return res.status(403).json({ error: err });
  }
};

To test this endpoint, try making request to the following url by sending user._id

http://localhost:8000/api/profile/xxxxxxxxx