avatarNikos Oikonomou

Summary

This section provides instructions for setting up a new NestJS project, including Node.js installation with NVM, NestJS CLI installation, project initialization, and basic commands for running, testing, and linting the application.

Abstract

The provided content is a guide for developers to create a new NestJS project from scratch. It begins with the installation of Node.js using the Node Version Manager (NVM) to ensure compatibility with NestJS. Once Node.js is installed, the NestJS Command Line Interface (CLI) is globally installed via npm, which is then used to generate a new NestJS application with a name of the developer's choice. The guide also covers saving the current Node.js version for consistency across development environments and provides essential npm scripts for starting the application in different modes, running tests, and maintaining code quality through linting and formatting. The article concludes by directing readers to additional resources, including an example repository, the official NestJS documentation, and the NVM GitHub repository.

Opinions

  • The use of NVM is recommended for managing Node.js versions, suggesting a preference for flexibility and consistency in development environments.
  • The guide emphasizes the importance of using the NestJS CLI for scaffolding new projects, indicating a reliance on this tool for efficient project setup.
  • By providing commands for different npm scripts, the content conveys the significance of testing and maintaining code quality as integral parts of the development workflow.
  • The inclusion of links to an example repository and official documentation suggests that the author values practical examples and comprehensive learning resources for developers to reference.

NestJS - Getting Started

In this section, we’ll create a new NestJS project and execute some basic setup steps to start the development.

This section is part of a larger guide.

Install NodeJS using Node Version Manager.

# Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash 
# install latest nodejs version
nvm install node # alternatively nvm install <your-desired-node-version>

Project initialization

# First of all we need to install NestJS CLI
npm i -g @nestjs/cli
# Generate the NestJS repository
nest new nestjs-app # you can select your desired application name
cd nestjs-app       # navigate to your app’s root directory
# Save your current node version for future usage
node -v > .nvmrc    # saves current nodejs version
nvm use             # loads and uses saved nodejs version

Now you have a fully operational NestJS project so you can start the development. You can verify that everything went well by running your default application:

npm run start      # development
npm run start:dev  # watch mode
npm run start:prod # production mode

Or test your code

npm run test     # unit tests
npm run test:e2e # e2e tests
npm run test:cov # test coverage

Or fix its quality:

npm run format && npm run lint

Now that everything is set up we can start the development. But before that let’s showcase some of the NestJS basics.

Useful Links:

Nodejs
Nestjs
Web Development
Backend
Recommended from ReadMedium