Skip to content

Hatching the Nest – Installing NestJS Like a Pro (or a Chicken πŸ”) ​

So you've met NestJS – the TypeScript-powered, Angular-inspired server-side superhero. Now it's time to install it, feed it some code, and watch it fly like... well, like a chicken with superpowers.

πŸ› οΈ Step 1: Prerequisites – Tools of the Trade ​

Before you jump into the nest, make sure your toolbox is ready:

  • πŸ§™ Node.js (v20+): The wise old wizard who runs your code

    Install it from: https://nodejs.org

  • πŸ§™ npm or yarn: The spellbooks (aka package managers)

You can check them like a boss:

bash
node -v
npm -v

If you see versions and not weird errors, congrats! You're ready.

🐣 Step 2: Global Nest CLI – The Nest Egg ​

You only need to hatch this once:

bash
npm i -g @nestjs/cli

πŸ—―οΈ This gives you the magical nest command, which is basically the Harry Potter wand for backend devs.

πŸ§ͺ Step 3: Create Your Nest – A New Project ​

Run this spell:

bash
nest new awesome-nest-app

And Nest will ask you to:

  • Pick a package manager (npm or yarn β€” pick your poison)
  • Then it installs everything like a wizard quietly brewing a potion.

You’ll get:

awesome-nest-app/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app.controller.spec.ts
β”‚   β”œβ”€β”€ app.controller.ts
β”‚   β”œβ”€β”€ app.module.ts
β”‚   └── app.service.ts
β”œβ”€β”€ main.ts
β”œβ”€β”€ package.json
└── tsconfig.json

Here's a brief overview of those core files:

File NameDescription
app.controller.tsA basic controller with a single route.
app.controller.spec.tsThe unit tests for the controller.
app.module.tsThe root module of the application.
app.service.tsA basic service with a single method.
main.tsThe entry file that uses NestFactory to create a Nest application instance.

πŸŽ‰ You’re now the proud parent of a brand-new NestJS app. Cute, huh?

πŸƒ Step 4: Run Like the Wind ​

Get inside your nest:

bash
cd awesome-nest-app

And run it:

bash
npm run start

To watch for changes in your files, you can run the following command to start the application:

bash
npm run start:dev

Boom πŸ’₯! Your server is alive at:

http://localhost:3000

Open your browser and get a warm welcome:

Hello World!

πŸ”₯ Bonus: Add Swagger, Because You’re Fancy ​

Install Swagger to make your APIs strut like supermodels:

bash
npm install --save @nestjs/swagger swagger-ui-express

Add this in main.ts to unleash the docs:

ts
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";

const config = new DocumentBuilder()
  .setTitle("My Nest API")
  .setDescription("Swagger is here to flex your endpoints πŸ’ͺ")
  .setVersion("1.0")
  .addBearerAuth()
  .build();

const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup("api", app, document);

Now visit:

http://localhost:3000/api

and boom, you got API docs ✨.

πŸ₯ Conclusion ​

Congratulations! You've just installed and launched your first NestJS app. You’re now officially a Nestling Developerβ„’, ready to build mighty server-side apps.

Stay tuned for the next chapter: "πŸ“¦ Modules – Like IKEA, But with Code."


Happy hacking, and may your backend never return a 500!

Built by noobs, for noobs, with love πŸ’»β€οΈ