julian shen
julian shen

Reputation: 3

Error when running js on mac via node.js. How to fix?

I have created a .js file in a text editor and tried to run it via node js:

var pizzaDoge = require('fs')
pizzaDoge.writeFile("/index.html", "<h1>doge is fat</h1>", function(error) {
  if (error) {
    return console.log(error)
  } else {
    return console.log("you fed the doge!")
  }
})

when I try to run the program using node using "node index.html" in the command line software this pops out

{ Error: EACCES: permission denied, open '/index.html'
errno: -13,
code: 'EACCES',
syscall: 'open',
  path: '/index.html' }

just in case the error no. matters to which computer I am using I use Mac. Thanks for the help.

Upvotes: 0

Views: 48

Answers (1)

Ryan W
Ryan W

Reputation: 6173

On Mac, the root folder(/) requires root permission to access

Please try to use ./index.html instead of /index.html for creating files under your current folder

Upvotes: 1

Related Questions