How I set up my NestJs project

I am among the millions of people who feel lazy to setup a project. I so wish if there was a 1 click setup for everything. I recently chose NestJs – the express based framework of node for my new project. I am yet to see a better framework till date on nodeJs.

Just in case anyone is feeling too lazy to setup, here are the steps I followed –

  1. Install the nestjs CLI – the CLI makes it super easy to automate tasks. Believe me you will use this a lot while setting up new modules, controllers and services.
$ npm install -g @nestjs/cli

2. Create the project 😛

$ nest new <project-name>

3. Install MongoDb – I don’t know why, but I am in love with this database. I especially love writing aggregations in mongo. NestJs provides wrappers via which you can talk to Mongo using Mongoose.

$npm install --save @nestjs/mongoose mongoose

Open your project and go to app.module.ts and add this line in the imports array –


@Module({
  imports: 
  [
      MongooseModule.forRoot('mongodb://localhost/manager'),
      ...

Oh yeah, you do need to install MongoDB in your system. Go here for installing MongoDB. Make sure to install the community edition.

4. Last but not the least, install the class-validator and class-transformer npm packages. These are used for DTOs. A DTO is basically what validates your request and response JSONs.

There it is. Happy coding ! 😀

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.