https://github.com/the3dgar/backend_personal-utils
This is an utils project
https://github.com/the3dgar/backend_personal-utils
backend express typescript
Last synced: 2 months ago
JSON representation
This is an utils project
- Host: GitHub
- URL: https://github.com/the3dgar/backend_personal-utils
- Owner: The3dgar
- Created: 2022-08-12T21:46:45.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-17T16:27:21.000Z (almost 4 years ago)
- Last Synced: 2025-03-11T21:44:11.370Z (over 1 year ago)
- Topics: backend, express, typescript
- Language: TypeScript
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# personal utils
def: this is a repo with utils backend tools, like validators, errors-handlers, etc... motivated for a lazy spirit to rebuild code
## 1 req.body validator
### dependencies:
- express-validator
### how to use:
- check validators/route-validatior
### example:
```
import { authValidations, authValidationsTypes } from '../validations/auth-validation';
const router = express.Router();
type SignUpRequest = {
email: string;
password: string;
};
router.post(
'/api/users/signup',
authValidations(authValidationsTypes.VALIDATE_SIGNUP),
(req, res) => {
...
}
);
```
## 2 Error Handler
### dependencies:
- express-async-errors
### how to use:
- check errors/custom-error.ts
### example:
in index.ts
````
import express from 'express';
import 'express-async-errors';
import { errorHandler } from './middlewares/error-handler';
import { NotFoundError } from './errors/not-found-error';
.
.
.
// after the app routes
app.all('*', async () => {
throw new NotFoundError();
});
app.use(errorHandler);
````