Skip to content

Instantly share code, notes, and snippets.

@AlexZeitler
Last active October 4, 2022 21:50
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexZeitler/64ca2b964874871c1c53e3cf48207e4d to your computer and use it in GitHub Desktop.
Save AlexZeitler/64ca2b964874871c1c53e3cf48207e4d to your computer and use it in GitHub Desktop.
fs.stat with async/await in Node.js 8
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