Nest CLI
New in version 5 of Nest there is a CLI that allows for command line generation of projects and files. The CLI can be installed globally with:
npm install -g @nestjs/cli
Or through Docker with:
docker pull nestjs/cli:[
version]
A new Nest project can be generated with the command:
nest new[
project-name]
This process will create the project from a typescript-starter and will ask for the name
, description
, version
(defaults to 0.0.0), and author
(this would be your name). After this process is finished you will have a fully setup Nest project with the dependencies installed in your node_modules
folder. The new
command will also ask what package manager you would like to use, in the same way that either yarn
or npm
can be used. Nest gives you this choice during creation.
The most used command from the CLI will be the generate
(g) command, this will allow you to create new controllers
, modules
, servies
or any other components that Nest supports. The list of available components is:
class
(cl)controller
(co)decorator
(d)exception
(e)filter
(f)gateway
(ga)guard
(gu)interceptor
(i)middleware
(mi)module
(mo)pipe
(pi)provider
(pr)service
(s)
Note that the string in the brackets is the alias for that specific command. This means that instead of typing:
nest generate service[
service-name]
In your console, you can enter:
nest g s[
service-name]
Lastly, the Nest CLI provides the info
(i) command to display information about your project. This command will output information that looks something like:
[
System Information]
OS Version : macOS High Sierra NodeJS Version : v8.9.0 YARN Version : 1.5.1[
Nest Information]
microservices version : 5.0.0 websockets version : 5.0.0 testing version : 5.0.0 common version : 5.0.0 core version : 5.0.0