|
| 1 | +--- |
| 2 | +sidebar_position: 4 |
| 3 | +title: "Final Challenge: The Terminal Cow" |
| 4 | +sidebar_label: "4. NPM Challenge" |
| 5 | +description: "Put your NPM skills to the test by creating a project and running your first package." |
| 6 | +--- |
| 7 | + |
| 8 | +It’s time to use your "Developer Warehouse" (NPM) to add a fun feature to your computer. We are going to install a package called **Cowsay**. |
| 9 | + |
| 10 | +Why? Because if you can install a cow that talks, you can install **React**, **Vite**, or any other professional tool! |
| 11 | + |
| 12 | +## The Mission Blueprint |
| 13 | + |
| 14 | +Follow these **4 Steps** to complete your graduation: |
| 15 | + |
| 16 | +### 1. The Setup |
| 17 | +Create a brand new folder on your computer named `my-npm-adventure`. Open your terminal (or VS Code) inside that folder and initialize your "Recipe File": |
| 18 | +```bash |
| 19 | +npm init -y |
| 20 | +``` |
| 21 | + |
| 22 | +*Check: Do you see a `package.json` file now? Good!* |
| 23 | + |
| 24 | +### 2. The Installation |
| 25 | + |
| 26 | +Now, let's "borrow" the Cowsay code from the warehouse. |
| 27 | + |
| 28 | +```bash |
| 29 | +npm install cowsay |
| 30 | +``` |
| 31 | + |
| 32 | +*Check: Open your `package.json`. You should see `cowsay` listed under `"dependencies"`. Also, notice the giant `node_modules` folder that just appeared!* |
| 33 | + |
| 34 | +### 3. The Execution |
| 35 | + |
| 36 | +To run a package we just downloaded, we use a special command called `npx` (think of it as "NPM Execute"). |
| 37 | + |
| 38 | +```bash |
| 39 | +npx cowsay "CodeHarborHub is the best!" |
| 40 | +``` |
| 41 | + |
| 42 | +**Look at your terminal!** A cow should appear, speaking the words you typed. You didn't write the code to draw that cow; you used the power of NPM! |
| 43 | + |
| 44 | +## Level Up: Create a Custom Script |
| 45 | + |
| 46 | +Professional developers don't like typing long commands. They create **Shortcuts**. |
| 47 | + |
| 48 | +1. Open your `package.json` file. |
| 49 | +2. Find the `"scripts"` section. |
| 50 | +3. Add a new line called `"moo"` like this: |
| 51 | + |
| 52 | +```json {4} |
| 53 | +"scripts": { |
| 54 | + "test": "echo \"Error: no test specified\" && exit 1", |
| 55 | + "start": "node index.js", |
| 56 | + "moo": "cowsay CodeHarborHub Graduation!" |
| 57 | +}, |
| 58 | +``` |
| 59 | + |
| 60 | +4. Now, go back to your terminal and run your shortcut: |
| 61 | + |
| 62 | +```bash |
| 63 | +npm run moo |
| 64 | +``` |
| 65 | + |
| 66 | +## What did you just learn? |
| 67 | + |
| 68 | +By completing this challenge, you have mastered the **Standard Developer Workflow**: |
| 69 | + |
| 70 | +* **Init:** Created a project foundation. |
| 71 | +* **Install:** Brought in external code. |
| 72 | +* **Execute:** Ran a third-party tool. |
| 73 | +* **Script:** Created a custom automation shortcut. |
| 74 | + |
| 75 | +## Graduation Checklist |
| 76 | + |
| 77 | +* [x] I successfully created a `package.json` using `npm init`. |
| 78 | +* [x] I installed a package and saw it in `node_modules`. |
| 79 | +* [x] I ran a package using the `npx` command. |
| 80 | +* [x] I created a custom script and ran it with `npm run`. |
| 81 | + |
| 82 | +:::success 🎉 CONGRATULATIONS! |
| 83 | +You have officially completed the **NPM Basics** module. You are no longer just a "Coder"—you are a "Developer" who knows how to use the global ecosystem of software. |
| 84 | + |
| 85 | +**What's Next?** You are now fully prepared for the **Intermediate Frontend** track, where we will use NPM to install **React** and build modern, high-speed web applications! |
| 86 | +::: |
0 commit comments