mkdir menu-api
cd menu-api
npm init -y
npm i express dotenv cors helmet
npm i -D typescript
npm i -D @types/node @types/express @types/dotenv @types/cors @types/helmet
npx tsc --init
echo PORT=7000 > .env
mkdir src
touch src/index.ts
npm i -D ts-node-dev
--respawn: Keep watching for changes after the script has exited.
--pretty: Use pretty diagnostic formatter (TS_NODE_PRETTY).
--transpile-only: Use TypeScript's faster transpileModule (TS_NODE_TRANSPILE_ONLY).
src/index.ts: This is the application's entry file.
npm run dev
Abaixo a chamado de alguns endpoints via curl.
curl http://localhost:7000/api/menu/items -i
curl http://localhost:7000/api/menu/items/2 -i
curl -X POST -H 'Content-Type: application/json' -d '{
"name": "Salad",
"price": 499,
"description": "Fresh",
"image": "https://cdn.auth0.com/blog/whatabyte/salad-sm.png"
}' http://localhost:7000/api/menu/items -i
curl -X PUT -H 'Content-Type: application/json' -d '{
"name": "Spicy Pizza",
"price": 599,
"description": "Blazing Good",
"image": "https://cdn.auth0.com/blog/whatabyte/pizza-sm.png"
}' http://localhost:7000/api/menu/items/2 -i
curl -X DELETE http://localhost:7000/api/menu/items/2 -i
https://auth0.com/blog/node-js-and-typescript-tutorial-build-a-crud-api/