• mac 安装nodemon报错和解决方法 npm i nodemon -g


    mac安装nodemon报错和解决方法

    运行npm install -g nodemon报错

    ~ % npm install -g nodemon
    npm ERR! code EACCES
    npm ERR! syscall mkdir
    npm ERR! path /usr/local/lib/node_modules/nodemon
    npm ERR! errno -13
    npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/nodemon'
    npm ERR!  [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/nodemon'] {
    npm ERR!   errno: -13,
    npm ERR!   code: 'EACCES',
    npm ERR!   syscall: 'mkdir',
    npm ERR!   path: '/usr/local/lib/node_modules/nodemon'
    npm ERR! }
    npm ERR! 
    npm ERR! The operation was rejected by your operating system.
    npm ERR! It is likely you do not have the permissions to access this file as the current user
    npm ERR! 
    npm ERR! If you believe this might be a permissions issue, please double-check the
    npm ERR! permissions of the file and its containing directories, or try running
    npm ERR! the command again as root/Administrator.
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     /Users/phoenix/.npm/_logs/2023-09-10T03_45_27_491Z-debug-0.log
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    解决方案:是权限问题,可以通过sudo npm install -g nodemon,赋予权限后安装

    ~ % sudo npm install -g nodemon
    Password:
    
    added 34 packages, and audited 35 packages in 8s
    
    3 packages are looking for funding
      run `npm fund` for details
    
    found 0 vulnerabilities
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    最后查看安装成功没

    % nodemon -v 
    3.0.1
    
    • 1
    • 2

    OK

    npm全局软件包-nodemon

    本地软件包和全局软件包区别,体验 nodemon 的使用。以前,开发一个node服务时,每次更改文件,都需要重启一下,服务才能生效。这使我们的开发效率降低了很多。nodemon可以随时监听文件的变更,自动重启服务,我们开发时只需关注代码即可,不再需要手动重启服务。

    1. 软件包区别:

      • 本地软件包:当前项目内使用,封装属性和方法,存在于 node_modules
      • 全局软件包:本机所有项目使用,封装命令和工具,存在于系统设置的位置
    2. nodemon 作用:替代 node 命令,检测代码更改,自动重启程序

    3. 使用:

      1. 安装:sudo npm install -g nodemon (-g 代表安装到全局环境中)
      2. 运行:nodemon 待执行的目标 js 文件
    4. 需求:使用 nodemon 命令来启动准备好的项目,然后修改代码保存后,观察终端重启应用程序

     % nodemon server.js
    [nodemon] 3.0.1
    [nodemon] to restart at any time, enter `rs`
    [nodemon] watching path(s): *.*
    [nodemon] watching extensions: js,mjs,cjs,json
    [nodemon] starting `node server.js`
    2023-09-10
    [nodemon] clean exit - waiting for changes before restart
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    好了,我们可以正常使用nodemon了

    本次的分享就到这里了!!!

  • 相关阅读:
    完全可复制、经过验证的 Go 工具链
    部署LVS-NAT群集实验 待续。。
    开源图像分类工具箱MMClassification安装及使用示例
    SpringCloud学习
    C/C++语言标准
    电商运营怎么去学?如何打造爆品?
    DockerCompose安装、使用 及 微服务部署实操
    hashmap的一些坑
    从0到1 Webpack搭建Vue3开发、生产环境
    网络安全工作的随想
  • 原文地址:https://blog.csdn.net/qq_37255976/article/details/132789468