Skip to content

Repository files navigation

API REST - Node.js - Fastify

Libs

Install Fastify

npm install fastify

Install typescript

npm install -D typescript
npm install -D @types/node

To run the server, we need to convert the TS file to JS with the command line below:

npx tsc src/server.ts

Now after the JS file is created, we can send the node to execute the JS file:

node src/server.js

To make the TS file conversion process more efficient and run node on the converted file, we will install a tool called TSX. But we must remember that this tool is only for "development mode".

npm install tsx -D
npx tsx src/server.ts
npm run dev

We will use the query builder Knex.js for the database. https://knexjs.org

npm install knex sqlite3

To create a migration:

npm run knex -- migrate:make create-documents

Environment variables: Install DotENV

npm install dotenv

we will use the ZOD lib for data validation in our environment variables

npm install zod

Test whit Vitest https://vitest.dev

npm install vitest -D

For testing, the interesting thing is not to "raise a server", but for the agent to be able to make requests. To do this we will install the supertest library.

npm install supertest -D
npm install -D @types/supertest
npm run test

About

Api REST em Node.js utilizando o framework Fastify

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages