This repo contains a RESTful API using Express.js and TypeScript. The API allows users to create and retrieve blog posts.
- Node.js [https://nodejs.org/]
- Express.js [https://expressjs.com/]
- Typescript [https://www.typescriptlang.org/]
- Sequelize ORM [https://sequelize.org/]
- Jest.js [https://jestjs.io/] for unit tests
- Joi.js [https://joi.dev/] for input validation
- SQLite [https://sqlite.org/] for datastorage
POST /v1/users/login
: Does the user login and return JWT tokenGET /v1/posts
: List all postsGET /v1/posts/:id
: Get a post detailsPOST /v1/posts
: Create a new postPUT /v1/posts/:id
: Update an existing postDELETE /v1/posts/:id
: Delete a post
Please install the most recently Node.js version if you don't have it. Recommended v20.14.0 or later:
# installs nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# download and install Node.js
nvm install 20
# verifies the right Node.js version is in the environment
node -v # should print `v20.14.0`
# verifies the right NPM version is in the environment
npm -v # should print `10.7.0`
Open your terminal and clone this repo:
git clone https://github.com/lucasmendonca/express-typescript-api.git
Go to the project directory:
cd express-typescript-api
Install node dependencies:
npm i
For the matter of simplicity this repo uses a local SQLite database. There is one database-init script which creates required tables and sample data. Please run the following:
npm run init
Start the server in development mode (not receomend for production):
npm run dev
To run tests, run the following command:
npm run test
To verify test coverage run the command below and then open the generated file coverage/lcov-report/index.html
for coverge details:
npm run coverage
To build the project, run the following command (recomended for any non-dev environemt):
npm run build
Then, start the server in production mode:
npm run start
Default values are provided but in order to overwrite default configurations you will need to add the following environment variables to your .env
file. Plese clone and rename the .env.sample
file.
PORT=<<SERVER_DEFAULT_PORT>>
jwtSecret=<<JWT_SECRET_KEY>>