-
Clone this repository to your local machine.
-
Navigate to the project folder in your terminal.
-
Install the dependencies:
npm install
In this task you will build a command-line tool that fetches cocktail recipes from an API and writes the results to a markdown file. All your work will be in the file task-1/cocktail.js.
The starter code already handles command-line arguments and sets up the output path for you. Your job is to fill in the try/catch block with working code. You may add helper functions above main() as needed.
-
Run the program with a cocktail name:
node task-1/cocktail.js margarita
-
When finished, the program should create a file
task-1/output/margarita.md. -
Run the tests to check your work:
npm run test:cocktail
Complete the four numbered steps inside main():
-
Fetch data from the API — Use
fetch()withasync/awaitto call the API at the givenurl. Parse the JSON response. If the response is not OK, throw an error. -
Generate markdown content — Transform the returned drink data into a markdown string. The API may return multiple drinks for a single search term (e.g. searching "margarita" returns several variations). Your output must include all of them.
-
Write the file — Use
fs/promises(writeFile) to write the generated markdown to the file path given byoutPath. -
Handle errors — In the
catchblock, log a helpful error message to the console.
Look at the example files in task-1/examples/ to see exactly what your output should look like. Each drink should include:
- A level-2 heading (
##) with the drink name - A thumbnail image (use the URL from
strDrinkThumbwith/mediumappended) - Category and Alcoholic (Yes/No) fields
- A list of ingredients with their measures
- Instructions and the glass to serve in
The API documentation is at: https://www.thecocktaildb.com/api.php
The search endpoint used in the starter code returns an object with a drinks array. Each drink object has properties like strDrink, strDrinkThumb, strCategory, strAlcoholic, strInstructions, strGlass, and numbered ingredient/measure pairs (strIngredient1…strIngredient15, strMeasure1…strMeasure15). Not all ingredient slots are filled — stop when the value is null or empty.
- You will need to import
fsfrom'fs/promises'to write the file. - The API can return
nullfor thedrinksproperty if no cocktail is found — handle this case. - Ingredient/measure pairs are numbered 1–15. Loop through them and skip any that are empty or
null. - Compare your output against the example files to make sure formatting matches.
In this task you will implement the service functions that connect the Post Central CLI app to its API server. All your work will be in the file task-2/src/services.js.
The file contains stub functions that currently throw a "Not implemented" error. Your job is to replace each stub with a working fetch call to the API.
- Run
npm run task2to start the app. You will see "Not implemented" errors for any function you haven't completed yet. - Run the tests for each stage as you go (see below) to check your work.
The registerUser function is already fully implemented for you. Study it carefully — all other functions follow the same pattern:
- Call
fetch()with the correct URL, method, headers, and body. - Check
response.ok. Iffalse, throw an error. - Return the parsed JSON response (or nothing for DELETE requests).
Implement the following function:
getMe()—GET /users/meRequires theAuthorizationheader with the stored token:Bearer ${getToken()}. Returns:{ user: string }
Run the tests: npm run test:get
Implement the following function:
loginUser(name, password)—POST /users/loginSame pattern asregisterUserbut posts to/users/login. Returns:{ user: string, token: string }
Run the tests: npm run test:post
Implement the remaining functions:
-
createPost(text)—POST /postsRequires bothContent-TypeandAuthorizationheaders. Body:{ text }. Returns:{ id: number, text: string, user: string } -
getPosts()—GET /posts/meRequires theAuthorizationheader. Returns: array of{ id, text, user } -
updatePost(id, text)—PUT /posts/:idRequires bothContent-TypeandAuthorizationheaders. Body:{ text }. Returns:{ id: number, text: string } -
deleteUser()—DELETE /users/meRequires theAuthorizationheader. No response body. -
deletePost(id)—DELETE /posts/:idRequires theAuthorizationheader. No response body.
Run the tests: npm run test:crud
- Unauthenticated endpoints (
registerUser,loginUser) only need theContent-Typeheader. - All other endpoints also need the
Authorizationheader:Bearer ${getToken()}. - For
DELETErequests there is no JSON response body to parse. - Run all tests at once with
npm run test:run.