Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. const fs = require('fs');
  2.  
  3. function fileSize(fileName, cb) {
  4. if(typeof fileName !== 'string') {
  5. return process.nextTick(cb, new TypeError('argument should be string'));
  6. }
  7.  
  8. fs.stat(fileName, (err, stats) => {
  9. if(err) {
  10. return cb(err);
  11. }
  12.  
  13. cb(null, stats.size);
  14. });
  15. }
  16.  
  17. fileSize(1, (err, stats) => {
  18. if(err) throw err;
  19.  
  20. console.log(`Size in KB: ${size/1024}`);
  21. });
  22.  
  23. console.log('Hello!');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement