Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am seeing tutorials with NPM and Node.js that have the ng package handler. However, they run this straight from the command prompt. I am curious if I am missing something to install to run commands like ng serve for example, without having to preface them with npm run like npm run ng serve --open ?

Thank you!

Note that you will be using the cli only for Angular 2+ versions. If you want something for angularjs there is a non official cli and it's only for component generation. Luiz Carlos Aug 7, 2018 at 11:53

It's not recommended to install @angular/cli globally. Some projects will use different version of angular@cli and executing ng commands will have unexpected result.

Instead, install locally into dev dependencies with:

npm install --save-dev angular@cli

or Yarn:

yarn add --dev angular@cli

After you install locally, you can setup various npm scripts to execute ng commands:

scripts: {
    "dev": "ng serve"

Run the script:

npm run dev

** Please note, if you have globally installed angular@cli, running the commands mentioned above will use the local angular@cli package from node_modules/.bin.

Also, npx is a tool intended to help round out the experience of using packages from the npm registry. You can read about it more here

you don't really need to add dev task. npm run ng -- serve would work just fine... To open browser npm run ng -- server --open – AdityaParab Aug 7, 2018 at 14:18

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.