This is a template for a express API with typescript and yup validation.
- Clone the repository
- install dependencies with
npm install
oryarn
- Create a .env file and set the environment variables (e.g., PORT, DATABASE_URL, etc.).
- Run the development server using
npm run dev
oryarn dev
|-- dist/
|-- src/
|-- middleware/
|-- routes/
|-- schemas/
|-- utils/
|-- types/
|-- tests/
.env
dist
: This folder contains the compiled code. may not exist if you haven't run the build script yet.src
: This folder contains the source code.src/middleware
: This folder contains the middlewares. functions that have access to the request and response objects before the request is handled by the route.src/routes
: This folder contains the routes. functions that handle the request and send the response.src/schemas
: This folder contains the schemas. functions that validate the request body.src/utils
: This folder contains the utils. functions that are used in multiple places.src/utils/types
: This folder contains the types. typescript types.src/tests
: This folder contains the tests. functions that test the code.
The environment variables are stored in the .env
file.
example env file:
PORT=3000
npm run dev
oryarn dev
: Runs the development servernpm run build
oryarn build
: Builds the project for production into thedist
foldernpm run start
oryarn start
: Runs the production servernpm run test
oryarn test
: Runs the tests [!!!]
!!!: The tests are not implemented in this template as they are personal/situational preference. You can use any testing framework you want
Testing is an important part of any software development project. It helps ensure that your code is working correctly and prevents bugs and errors from being introduced into your application.
Here are some recommendations:
- Jest: https://jestjs.io/
- Mocha: https://mochajs.org/
- Jasmine: https://jasmine.github.io/
- Ava: https://github.com/avajs/ava
You can also use a test framework that is not listed here.
MIT
Diego Vallejo - @DiegoVallejoDev
Feel free to contribute to this project by opening a pull request or an issue.