Last active
October 4, 2022 21:50
-
-
Save AlexZeitler/64ca2b964874871c1c53e3cf48207e4d to your computer and use it in GitHub Desktop.
fs.stat with async/await in Node.js 8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const asset = require('assert'); | |
const fs = require('fs'); | |
const { promisify } = require('util'); | |
const stat = promisify(fs.stat); | |
describe('async stat', () => { | |
it('should not throw if file does exist', async () => { | |
try { | |
const stats = await stat(path.join('path', 'to', 'existingfile.txt')); | |
assert.notEqual(stats, null); | |
} catch (err) { | |
} | |
}); | |
}); | |
describe('async stat', () => { | |
it('should throw if file does not exist', async () => { | |
try { | |
const stats = await stat(path.join('path', 'to', 'not', 'existingfile.txt')); | |
} catch (err) { | |
assert.notEqual(err, null); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment