Skip to content

Instantly share code, notes, and snippets.

@pitaj
Created October 29, 2017 20:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pitaj/047faae18463835a8b7697e2964a341e to your computer and use it in GitHub Desktop.
Save pitaj/047faae18463835a8b7697e2964a341e to your computer and use it in GitHub Desktop.
Demonstrate different error codes being thrown depending on platform when attempting to write to a read-only file
const fs = require('fs');
const path = require('path');
const code = '444';
const filename = '00000';
const content = 'abcdefghijklmnopqrstuvwxyz';
const filePath = path.join(__dirname, filename);
// set up a read-only file
fs.writeFileSync(filePath, content);
fs.chmodSync(filePath, '444');
fs.writeFile(filePath, content, function (err) {
throw err;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment