DEV Community

Rajesh Kumar Yadav
Rajesh Kumar Yadav Subscriber

Posted on • Updated on

Angular : How to run Angular CLI using localhost over https?

The easiest method you can find is to install browser-sync as a dev dependency.



npm install browser-sync --save-dev


Enter fullscreen mode Exit fullscreen mode

This will install a self-signed certificate and key for localhost, which you can now point to when adding the --ssl
switches.

Open your package.json in root folder of your angular project and change the start script to the following:



ng serve --ssl true --ssl-key /node_modules/browser-sync/lib/server/certs/server.key --ssl-cert /node_modules/browser-sync/lib/server/certs/server.crt


Enter fullscreen mode Exit fullscreen mode

Now, when you call ng start NPM will run ng serve with the additional SSL switches, and serve your site under HTTPS (e.g. https://localhost:4200).

Buy Me A Coffee

With all that being said, I highly recommend you keep learning!

Thank you for reading this article. Please feel free to connect with me on LinkedIn and Twitter.

Top comments (0)