-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: open browser on npm start #94
Conversation
@@ -155,4 +156,5 @@ MongoClient.connect(config.db, function(err, db) { | |||
}); | |||
*/ | |||
|
|||
opn("http://localhost:" + config.port); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@petermbenjamin Thanks for the PR. I see the convenience of automatically opening the app in the browser on starting the server. However, I am a bit unsure how this would work when the app is hosted on services such as heroku, especially as the opn
command has localhost hardcoded. We can possibly add a logic to conditionally execute the opn
command only if the hostname is localhost. Any thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I completely agree.
I see two options:
- Pull out this feature into a separate npm script (e.g.
"dev" : "npm start && opn http://localhost:4000"
) which users can start locally withnpm run dev
. - Check if
process.env.NODE_ENV === "development"
, then open a browser.
"grunt-npm-install": "^0.3.0", | ||
"grunt-retire": "^0.3.12", | ||
"mocha": "^2.4.5", | ||
"opn": "^4.0.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be moved to dependencies section as the code (server.js) has a direct dependency on this module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since opn
is expected to ever be executed in a development environment, I think we should keep it as a dev dependency, even if code has a direct dependency on this module.
Typically, users running this locally would have to npm install
before they npm start
, so dev dependencies will be installed as well.
How does this work within a container? |
@binarymist , I haven't thought of a container scenario. As for what happens if a browser tab already has nodegoat fetched,
|
Deployment via docker is one of the NodeGoat deployment strategies, as per the readme. |
When user types
npm start
, open a default browser tolocalhost:4000
.This is achieved by the
opn
npm package which is cross-platform and will work on Windows, Linux, & Mac.