Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var existsAsync = function(path) {
- return new Promise(function(resolve, reject) {
- fs.exists(path, function(exists) {
- // exists is a boolean
- if (exists) {
- // Resolve successfully
- resolve();
- } else {
- // Reject with error
- reject(new Error('path does not exist'));
- }
- });
- });
- // Use as a promise now
- existsAsync('/path/to/some/file').then(function() {
- console.log('file exists!');
- }).catch(function(err) {
- // file does not exist
- console.error(err);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement