Figure out how to pass a Node script to BROWSER
See original GitHub issueWe added support for BROWSER
env variable that is interpreted by OS-specific command.
On OS X, it runs open http://url.com -a <BROWSER>
.
However I’m not sure how to make it execute a Node script, and if it’s even possible. That would be the best for allowing use cases like #1096 and https://github.com/facebookincubator/create-react-app/issues/1450. It would be awesome to investigate how to get it working with a Node script (my naïve attempt at pointing it to a shell script with node env didn’t seem to work), and maybe implement some custom handling for JS extension if we don’t find a solution.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
How to interact with a node.js script in the browser?
Then, I want to pass the somevariable to the node script myfile.js, get the result back from myfile.js, and present the result in...
Read more >How to run Node.js (apps) in the browser? - CloudBoost
For my port I actually started out by passing process = {} to the bootstrapping function, having no clue how things work or...
Read more >How to share code between Node.js and the browser?
In this article, we will explore how to write JavaScript modules that can be used by both the client-side and the server-side applications....
Read more >Run Node.js scripts from the command line
Run Node.js scripts from the command line · Pass string as argument to node instead of file path · Restart the application automatically....
Read more >Node JS Tutorial: The Basics
Start a web browser (Chrome, Firefox). Issue URL http://localhost:3000/ . You shall see a hello-world message. To stop the server, press Ctrl-C ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Found a way to achieve this using the script option on MacOS.
The following works if a
development
profile has been created.https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles#w_starting-the-profile-manager
Set
BROWSER=open.js
in.env
.Then run
npm start
as usual.I think that the best choice is to spawn a child process to execute the node script if the
BROWSER
string ends in “.js”. It is the easiest way to support al operating systems.react-dev-utils uses
opn
to open the browser. This module uses the commandopen
on OS X,start
on Windows andxdg-open
on other platforms. I only use Linux, so I only know aboutxdg-open
, but I believe the other tools are designed in a similar way.xdg-open
is meant to be used in desktop sessions, like when the user double clicks a file. You click a photo, your photo viewer is opened. You click a video, your media player is opened. In settings, the user can choose what programs to use for each type of file. For security reasons, it is strongly discouraged to execute scripts when double clicked, opening the file with a text editor is a much better choice. This is what probably every Linux desktop environment does by default, since users could be tricked into double clicking malicious scripts.Handling the “.js” extension is much easier and secure.