angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Executing "ng serve" or "npm start" command browser is not opening automatically

Open deepaksibar opened this issue 10 years ago • 26 comments

  1. OS?
    Window 7
  2. Versions? angular-cli: 0.0.39 node: 5.4.1 os: win32 x64

I have generated a project using angular-cli by following steps given in installation section. Project is running right now. But i have to open browser manually by typing http://localhost:4200/ into browser.

Could it be possible like when user will execute "ng serve" or "npm start" command, browser will open automatically?

Please let me know if it is possible or give me any solution for this.

Thanks in advance.

-Deepak

deepaksibar avatar Jun 14 '16 14:06 deepaksibar

I don't think the intention is to open the browser automatically. When you visit the URL (http://localhost:4200) the browser should be refreshed automatically when changes occur in the code.

Trendy avatar Jun 14 '16 15:06 Trendy

We don't have this functionality at the moment, no. But I'll leave the issue open as a 'nice to have'.

filipesilva avatar Jun 17 '16 00:06 filipesilva

Yes, it would be nice to have this as an option.

Splaktar avatar Jun 18 '16 16:06 Splaktar

Thanks for response. On 17-Jun-2016 6:24 am, "Filipe Silva" [email protected] wrote:

We don't have this functionality at the moment, no. But I'll leave the issue open as a 'nice to have'.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/1081#issuecomment-226654711, or mute the thread https://github.com/notifications/unsubscribe/AQPGGMs-Ca05hHGeMFm_V1ZMdjVUvNFEks5qMfAngaJpZM4I1YYs .

deepaksibar avatar Jun 18 '16 17:06 deepaksibar

can we not use lite-server written by john papa to open the browser after ng server on inside ng serve

kamran-pervaiz avatar Jun 23 '16 10:06 kamran-pervaiz

There may be ambiguity between lite-server port and ng server port.

deepaksibar avatar Jun 27 '16 06:06 deepaksibar

I don't think the intention is to open the browser automatically. When you visit the URL (http://localhost:4200) the browser should be refreshed automatically when changes occur in the code.

@Trendy I would consider them 2 different features. The way i have seen the Refresh work is that you hit your site, the site has some javascript injected into it that listens for a command to tell it that something changed then it reloads the page. This is different from when you start the app sending a command to launch a browser and navigate to the URL.

If you never navigated to the url of your app then there would be no code running to listen when something changed. I guess its still doable but then you would probably need a browser plugin to listen instead

rburnham52 avatar Jul 06 '16 09:07 rburnham52

You could just change what npm start does in the package.json.

E.g. change "start": "ng serve" to "start": "start http://localhost:4201 & ng serve -port 4201" (for windows)

See http://stackoverflow.com/a/35261624 for Mac/Linux equivalents.

Or you could use the following if you want a cross platform solution: https://www.npmjs.com/package/open

ghost avatar Sep 18 '16 08:09 ghost

Thanks

On 18-Sep-2016 2:12 pm, "Chris Foster" [email protected] wrote:

You can just change what npm start does in the package.json.

E.g. change "start": "ng serve" to "start": "start http://localhost:4201 & ng serve -port 4201" (for windows)

See http://stackoverflow.com/a/35261624 for Mac/Linux equivalents.

Or you could use the following if you want a cross platform https://www.npmjs.com/package/open

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/1081#issuecomment-247834897, or mute the thread https://github.com/notifications/unsubscribe-auth/AQPGGLV_2xsh-qCSyJGUESUorsOuBj3dks5qrPldgaJpZM4I1YYs .

deepaksibar avatar Sep 18 '16 09:09 deepaksibar

Guys can you consider browser option? Like open in chrome or firefox.

applemate avatar Feb 22 '17 07:02 applemate

I like having the app launch the first time in the browser, like using browserSync with Gulp.

Checked ng-cli documentation, it's #ng start -o

https://github.com/angular/angular-cli/wiki/serve

rsprince avatar Mar 27 '17 20:03 rsprince

error ang

arbimauday avatar Jun 17 '17 05:06 arbimauday

This behavior should definitely be available, but through an option.
Right now, you can maybe use the npm opn module ?

EmmanuelDemey avatar Jun 17 '17 06:06 EmmanuelDemey

I have resolved issue. Issue is default browser. you can set browser help below image and run command ng serve --open.

image

kamlesh131986 avatar Jun 20 '17 10:06 kamlesh131986

As I mentioned, the functionality is there. There are a bunch of options on the serve command. READ THE DOCUMENTATION: ng serve --open OR ng serve -o

rsprince avatar Jun 20 '17 11:06 rsprince

Para que la ejecución sea automática es necesario ejecutar >ng serve -o

neapi666 avatar Aug 26 '17 06:08 neapi666

ng serve --open doesn't open any browser nor a new tab in an open browser, nor open the URL in an existing tab. Chrome is my default Windows 7 Pro 64-bit browser.

The instructions say "Using the --open (or just -o) option will automatically open your browser on http://localhost:4200/.", so I'm not sure what's meant by "open", and I've never heard it to mean "refresh" (which sounds like a misnomer a non-IT person would use).

Has this command ever actually opened a browser or a new tab, or opened the URL in an existing tab? What is this option actually programmed to do?

davehoo avatar Sep 28 '17 18:09 davehoo

@dhinged this command has worked for a while now, and it still seems to work as I've just tried it. I wonder why it doesn't work for you... for reference the library we use to open the browser is https://www.npmjs.com/package/opn.

filipesilva avatar Oct 02 '17 10:10 filipesilva

I apologize, trying it again today, it just took a while for the server to "boot up" but it did open a browser tab (after I'd opened it myself based on the instructions URL).

So basically I ran the command (either time), it looked like it was running, but there was no output for maybe 15 seconds so I figured it was just running. I then later noticed a ton of output from node, so I just need to wait. However it would be nice to initially see output saying "Starting up" or something indicating it's running but still processing.

Thanks for being there!

davehoo avatar Oct 08 '17 01:10 davehoo

Just go into your package.json, and add the -o flag. For example: "start": "ng serve -o", Now when you do npm start, it'll open up the browser window and right port for you and save you a few strokes on the keyboard.

kamok avatar Oct 16 '17 15:10 kamok