使用 angular 控制台工具时,如何在终端上 运行 ng 服务?

How to run ng serve on terminal when using angular console tool?

我正在使用 angular console 到 运行 并测试我的应用程序等。这工作正常。但是当我尝试通过终端 运行 它而不使用 angular 控制台时,它会抛出以下内容:-bash: ng: command not found.

我确保 node_module 通过 npm install 安装在特定项目下,using/installing 所有依赖项。

另外,当我尝试 运行 ng -v 时,我收到相同的消息:-bash: ng: command not found。我假设 @angular/cli 的全局安装在我的机器或类似的东西上不正确。

我一直在 SO 中搜索,发现了类似的问题,但我认为我的问题似乎有所不同。此外,我不是 100% 确定它是否与 angular 控制台有关,但我只是问自己为什么它在使用 angular console 时有效,但在直接使用终端时却无效?

任何提示如何solve/fix这个?

问题已根据

中的答案解决

解决方案:

# create a new directory where npm will install packages
$  mkdir ~/.node_modules

# set npm "prefix" config to that directory
$  npm config set prefix '~/.node_modules'

# append a line to your .zshrc instructing it to include that directory in your $PATH, making the executables known to the shell
$ echo 'export PATH=~/.node_modules/bin:$PATH' >> ~/.zshrc

# update current shell with new path (not needed for new sessions)
$ source ~/.zshrc