How can I (literally) open a file with Node? - node.js

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?

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.

Related

Is it possible to run a .net library inside nodejs?

I need to run the system.data.sqlite library which is a .net library that creates a password in the sqlite database, and for me to be able to read this database in nodejs I need to install this library. It's possible? If so how can I do this?
Your simplest option may be to create a stand-alone .NET program using the desired .NET library that does what you want. This stand-alone program can work off either command line arguments or environment variables or stdin depending what you need to send to the program in order to do its thing.
You can then run that stand-alone program from within nodejs using the child_process module. You can pass it arguments or retrieve results if necessary.

How to update the PATH variable in a platform agnostic way using node js

i am making a CLI to automate the installation process of a software. I install it in a directory like $HOME/.software-name/. Now i would like to know about a platfrom agnostic way to update the system PATH environment variable so that in the future the user can run the command easily.
I am not looking for a os specific way like setx on windows or writing to the ~/.bashrc. I would prefer a library to do the task or a builtin function.
i know that i can retrieve the env variable using process.env.variableName but setting it would not work outside the child process (ie, NodeJS). It does work inside the NodeJS process but that is obviously not what is wanted here.
Thanks :)

Launching a file using NodeJS

I was wondering how I could launch a file using nodejs. Specifically I wanted to be able to run a nodejs file and inside the code, it will open up a certain file on my local hard drive. So I want to know what is the best and safest file way to launch a file or application preferably not using exec?
Thank you
I would look at the documentation about child process. Here is the link if you would like it:
https://nodejs.org/dist/latest-v9.x/docs/api/child_process.html

Electron: securely delete a file from filesystem

I need to do a secure file deletion within a cross platform electron app, trying to avoid data remanence of those files, so a simple fs.unlink is not enough.
The effect I'd like to achieve is similar to the unix shred command.
I tried in a linux Environment where I could just invoke a shred with a direct system call, but I need it to work in a cross-platform environment (windows and osx in particular) and I didn't found any useful command or npm library.
Any suggestion on how this could be done?

Start app on mac os directly after installation

I'd like to know if it is possible to create a dmg file which can be installed by Drag&Drop - and which starts directly after this installation without having to be called manually again.
And if this is possible, I'd like to know whether I can pass arguments to the (nodejs) process which will be started directly after the installation.
I managed to pass parameters to the process when I call it manually after the installation, but I want to run it directly.
Any help will be appreciated!
Thanks!
I solved it: Instead of creating an app and wrapping it into a dmg, I created an app and wrapped it into a pkg. For pkgs it is possible to use postinstall scripts, so I started the application through this script.

Resources