๐ฆฅ RS-School task.
To run the project locally, you would have to download zip file with the repository or clone it to your computer. โจ
What things do you need to do in order to run our project locally? ๐ค
- Use node 20 LTS โก
- Installed .git on your computer. โ๏ธ
- Code Editor of your choice. ๐
- Installed npm. ๐ฆ
First make sure you have all the things listed in the previous section. Then clone our repository to your computer: ๐
git clone https://github.com/Quiddlee/node-crud-api.git
or download zip file manually with our repository.
Navigate into project folder and run ๐ฆ:
npm install
Create .env
file in the root of the project and add all necessary variables ๐ฅ.
You can find .env.example
as an example file in the project root or follow the lines below ๐บ:
PORT=YOUR_PORT
HOST=YOUR_HOST
Finally run a development server: ๐คฉ
npm run start:dev
Aaaaand you're done! ๐๐ฅณ
Here you can find all the scripts that are available in our project. ๐ฆ
Start the app in base
mode: โ
npm run start:dev
Start the app in multi
mode: ๐ชญ
npm run start:multi
Start the app in prod
mode: ๐ชถ
npm run start:prod
Lint the app with eslint
: ๐ฆ
npm run lint
Lint adn fix the app errors with eslint
: ๐จ
npm run lint:fix
Format the App with Prettier: ๐งน
npm run format
Format the App with Prettier fix: ๐
npm run format:fix
Type check the App with TypeScript: ๐ฆ
npm run type-check
Run unit-tests with Vitest: ๐งช
npm run test
In the project root folder, you can find a Postman collection that will make your life easier while working with the API. ๐
The API has the following endpoints:
Method | Endpoint | Description |
---|---|---|
GET | /users | Get all the users from the database |
GET | /users/:id | Get a single user by ID |
POST | /users | Create a new user in the database |
PUT | /users/:id | Update a user by ID |
DELETE | /users/:id | Delete a user by ID |
Endpoint | Body | Example |
---|---|---|
POST | /users | An object with the username age and hobbies {"username": "user", "age": 20, "hobbies": ["cooking", "sport"]} |
PUT | /users/:id | An object with the updated username age and hobbies {"username": "updated user", "age": 30, "hobbies": ["updated hobbie"]} |
Field | Type | Description |
---|---|---|
status | "success" or "fail" | Indicates whether the request was successful or not |
message | string | in case of failed result the response will contain message why it is failed |
data | Object or Array | The data returned by the request |
GET /users
{
"status": "success",
"data": {
"users": [
{
"username": "user",
"age": 20,
"hobbies": ["cooking", "sport", "programming"]
},
{
"username": "user2",
"age": 21,
"hobbies": ["sport", "programming"]
},
{
"username": "user3",
"age": 22,
"hobbies": ["hobbie"]
}
]
}
}
GET /users/:id Error case
{
"status": "fail",
"message": "๐ฏ User not found"
}