'Nodemon - app crashed - waiting for file changes before start
I am learning NodeJs on my own and I can not figure out what is wrong with my code. I am following a Youtube tutorial, seems I have the same code. I was also not able to install Nodemon globaly npm install-- nodemon
so I have done npm install -g nodemon
instead. Error message:
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
APP.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");
});
PACKAGE.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"
}
}
Solution 1:[1]
The error tells you what is wrong -- the account under which you are running npm i -g nodemon
doesn't have sufficient permissions to write to system files. This has nothing to do with your code.
Do sudo npm i -g nodemon
instead.
Solution 2:[2]
Have tried? may help
npm i --save-dev nodemon
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | laptou |
Solution 2 | Tesla |