14

I'm new in nodejs/nestjs, I want to build a new nest project and want to install nest cli as a command-line interface tool

I've tried on the following instruction from nest documentation the first step is to install nest/cli globally and when I tried the second steps which are using nest command it always end up showing an error that "nest" is not recognized as an internal or external command

step 1

$ npm i -g @nestjs/cli

step 2

$ nest new project-name

the error

'nest' is not recognized as an internal or external command,
operable program or batch file.

9 Answers 9

9

The global npm binaries are probably not on your PATH, you have to add them:

Run the command npm root -g to find out where your global modules are installed, e.g. C:\Users\<username>\AppData\Roaming\npm\node_modules.

Then add C:\Users\<username>\AppData\Roaming\npm (without node_modules) to your PATH.

Sign up to request clarification or add additional context in comments.

1 Comment

I added the global npm binary to the path following your response but it didn't work , but when I added specifically the nestjs C:\Users\<username>\AppData\Roaming\npm\node_modules\@nestjs\cli to the PATH and restarted vs code it worked , not sure why the first one didnt work though .
8
  1. Find the npm global path like this

npm root -g  
                       

enter image description here

  1. Open EnvironMent variable

enter image description here

  1. Select Environment Variables

enter image description here

  1. Double Click on user defined variable path

enter image description here

  1. Click on New Button and add the location in underlined row

enter image description here

  1. Now Take new command prompt and type where nest or nest Now it Works

enter image description here

Comments

4

npx @nestjs/cli new project-name

This works for me for creating a project but didn't work to create a module for example.

Comments

1

In most cases, it is better to use npx instead of installing global npm packages, since you'll always use the latest version.

Just replace nest with npx @nestjs/cli for any command:

npx @nestjs/cli new project-name

Comments

0

Fix the same problem by adding nest to system variables manually.

  1. On the Windows desktop, right-click My Computer.
  2. In the pop-up menu, click Properties.
  3. In the System Properties window, click the Advanced tab, and then click Environment Variables.
  4. In the System Variables window, highlight Path, and click Edit.
  5. In the Edit System Variables window, insert the cursor at the end of the Variable value field.
  6. If the last character is not a semi-colon (;), add one.
  7. After the final semi-colon, type the full path to the file you want to find. For example: path C:\jdk

  8. Click OK in each open window.

Step by step guide took from here

Comments

0

We need to install nest. in document cli- nest forum i found that.

npm install -g @nestjs/cli

hope that useful.

1 Comment

The asker wrote that s/he did that in step 1 already...
0
npm root -g

enter image description here

you can use core nodejs way

node "C:\Users\Hasif\AppData\Roaming\npm\node_modules\@nestjs\cli\bin\nest.js" new project-name

this will be work like original command

nest new project-name

Comments

0

First check the global path

npm root -g

Then make sure nest cli is installed inside the node_modules there. In my case I forgot that I'm using NVM and switch to version where it doesn't have nest cli installed.

Comments

0

For npm verson 10.9.2 or higher

  1. Run this command
    npm prefix -g
    It will return you path like
    C:\Users\AlFahad\AppData\Roaming

  2. Add this as path in environment variable like shown in image

  3. Then check version to of nest to verify if it solved your issue
    nest --version

    I solved this issue using following steps I hope it will be helpful for you too

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.