Nodemon -应用程序崩溃-启动前等待文件更改

dz6r00yl  于 2022-12-22  发布在  Node.js
关注(0)|答案(2)|浏览(180)

我正在学习NodeJs对我自己,我不能找出什么是错的,我的代码。我下面的Youtube教程,似乎我有相同的代码。我也无法安装Nodemon globaly npm install-- nodemon,所以我做了npm install -g nodemon代替。错误消息:

MacBook-Pro-de-Pierre-Alexandre:untitled folder Pierre-Alexandre$ npm install -g nodemon
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/nodemon/node_modules/graceful-fs
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/nodemon
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/nodemon/node_modules
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules/nodemon/node_modules/graceful-fs
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/nodemon/node_modules/graceful-fs'
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules/nodemon/node_modules/graceful-fs']
npm ERR!   stack:
npm ERR!    'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules/nodemon/node_modules/graceful-fs\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path:
npm ERR!    '/usr/local/lib/node_modules/nodemon/node_modules/graceful-fs' }
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 (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/Pierre-Alexandre/.npm/_logs/2019-08-10T22_44_05_357Z-debug.log

应用程序.JS

import express from "express";
import mysql from "mysql";

const db = mySQL.createConnection({
    host : "localhost",
    user : "root",
    password : "123456"
});


db.connect((err) => {
    if(err){
        console.log("bad!!!");
    }
    console.log("mySQL connected");
})



const app = express();

app.get("/createdb", (req, res) => {
    let sql = "CREATE DATABASE nodemySQL";
    db.query(sql, (err, resut) =>{
        if(err){
            console.log("data base creation failed");
        }
        res.send("database created...");

    });
});


app.listen("3000", () => {
    console.log("server started on port 3000 :D");
});

包.JSON

{
  "name": "tuto",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1",
    "mysql": "^2.17.1",
    "nodemon": "^1.19.1"
  }
}
zujrkrfu

zujrkrfu1#

这个错误告诉你出了什么问题--你运行npm i -g nodemon的帐号没有足够的权限写入系统文件,这与你的代码无关。
改为执行sudo npm i -g nodemon

mzillmmw

mzillmmw2#

试过吗?可能有用
npm i --保存-开发nodemon

相关问题