Skip to content

Instantly share code, notes, and snippets.

@sysyrin
Created June 16, 2019 03:44
Show Gist options
  • Save sysyrin/3dd94f248184a8a2cc22f3e195da0b03 to your computer and use it in GitHub Desktop.
Save sysyrin/3dd94f248184a8a2cc22f3e195da0b03 to your computer and use it in GitHub Desktop.
const fs = require('fs');
function fileSize(fileName, cb) {
if(typeof fileName !== 'string') {
return process.nextTick(cb, new TypeError('argument should be string'));
}
fs.stat(fileName, (err, stats) => {
if(err) {
return cb(err);
}
cb(null, stats.size);
});
}
fileSize(1, (err, stats) => {
if(err) throw err;
console.log(`Size in KB: ${size/1024}`);
});
console.log('Hello!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment