Bryce Johnson
Bryce Johnson

Reputation: 6901

How can I (literally) open a file with Node?

I'm creating a command-line utility with Node that will be able to open (launch) files for the user programmatically, using the application they would use to do so by default.

After reading through the docs, I don't think fs.open() can do that.

Is there any way to do this in Node without having to pull in shell scripts?

Upvotes: 1

Views: 95

Answers (1)

mscdex
mscdex

Reputation: 106696

You'd need to call a special OS-dependent program via child_process.exec() or child_process.spawn(). On Windows you'd use start, for OSX you'd use open, and for Linux you'd generally use xdg-open. You might look at using an already made module on npm for handling all these cases, such as open.

Upvotes: 6

Related Questions