Skip to content

Instantly share code, notes, and snippets.

@aherve
Last active May 25, 2017 07:41
Show Gist options
  • Select an option

  • Save aherve/8addcf4e7df5f13e3abbfc39acecd0ac to your computer and use it in GitHub Desktop.

Select an option

Save aherve/8addcf4e7df5f13e3abbfc39acecd0ac to your computer and use it in GitHub Desktop.
import { Request, Result } from 'express'
export async function showUser (req: Request, res: Result) {
try {
const user = await User.findOne({id: req.params.id})
if (user) {
res.status(200).send({user})
} else {
res.sendStatus(404)
}
} catch (e) {
res.status(500).send({error: e})
}
}
@fox1t
Copy link

fox1t commented May 25, 2017

I think that you meant import { Request, Response } from 'express' on the first line import and on (req: Request, res: Response) function declaration. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment