- System requirements
- Node.JS v16
- Set environment variables: create a
.env
file in the root directory, and copy the contents from .env.sample - Install dependencies
yarn
- Seed database
yarn seed
- Start the dev server
yarn dev
Instead of following the steps above, you can also use Docker to set up your environment.
- System requirements
- Run
docker-compose up
to spin up the dev server. - Enter
Ctrl-C
in the same same terminal ordocker-compose down
in a separate terminal to shut down the server.
You can use cURL or a tool like Postman to test the API.
You can log in as one of the seeded users with the following curl command:
curl --location --request POST 'localhost:8080/api/login' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "thomas",
"password": "123456"
}'
Then you can use the token that comes back from the /login request to make an authenticated request to create a new blog post
curl --location --request POST 'localhost:8080/api/posts' \
--header 'x-access-token: your-token-here' \
--header 'Content-Type: application/json' \
--data-raw '{
"text": "This is some text for the blog post...",
"tags": ["travel", "hotel"]
}'
yarn lint
: Runs linter.yarn prettier --write .
: Runs autoformatteryarn test
: This repository contains a non-comprehensive set of unit tests used to determine if your code meets the basic requirements of the assignment. Please do not modify these tests.yarn seed
: Resets database and populates it with sample data.
- If you encounter an error related to
secretOrPrivateKey
when attempting to make a request, please ensure you have created a .env file in the root directory as per the Getting Started instructions. - If you are on M1 mac, you might encounter
ERR_DLOPEN_FAILED
when you try to install dependencies locally then run the server in docker (or vice versa). In case of error, try removing thenode_modules
directory and restartdocker compose up
.