# try-open [![NPM version](https://img.shields.io/npm/v/try-open.svg?style=flat)](https://www.npmjs.com/package/try-open) [![NPM downloads](https://img.shields.io/npm/dm/try-open.svg?style=flat)](https://npmjs.org/package/try-open) [![Build Status](https://img.shields.io/travis/jonschlinkert/try-open.svg?style=flat)](https://travis-ci.org/jonschlinkert/try-open)

> Tries to open a file using fs.openSync (only necessary with sync), fails gracefully if the file path does not exist on the file system. Since fs.existsSync has been deprecated, this can be used as an alternative.

## Install
Install with [npm](https://www.npmjs.com/):

```sh
$ npm install try-open --save
```

See the node.js [fs.open documentation](https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback) for more details.

## Usage

```js
var fs = require('fs');
var tryOpen = require('try-open');

var fd = tryOpen('package.json', 'r');
//=> 17

// close the file
fs.closeSync(fd);
```

## Related projects

You might also be interested in these projects: 

* [copy](https://www.npmjs.com/package/copy): Copy files or directories using globs. | [homepage](https://github.com/jonschlinkert/copy)
* [delete](https://www.npmjs.com/package/delete): Delete files and folders and any intermediate directories if they exist (sync and async). | [homepage](https://github.com/jonschlinkert/delete)
* [fs-utils](https://www.npmjs.com/package/fs-utils): fs extras and utilities to extend the node.js file system module. Used in Assemble and… [more](https://www.npmjs.com/package/fs-utils) | [homepage](https://github.com/assemble/fs-utils)
* [write](https://www.npmjs.com/package/write): Write files to disk, creating intermediate directories if they don't exist. | [homepage](https://github.com/jonschlinkert/write)  

## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/try-open/issues/new).

## Building docs
Generate readme and API documentation with [verb][]:

```sh
$ npm install verb && npm run docs
```

Or, if [verb][] is installed globally:

```sh
$ verb
```

## Running tests
Install dev dependencies:

```sh
$ npm install -d && npm test
```

## Author
**Jon Schlinkert**

+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)

## License
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/jonschlinkert/try-open/blob/master/LICENSE).

***

_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on April 09, 2016._

