Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

How to change the port number?

Following this Angular 2 Basic's Video,

https://teamtreehouse.com/library/-your-first-angular-application,

I cannot use the 8080 as it is being used by other application. I've tried to change the serve script on package.json,

 "serve": "webpack-dev-server --config config/develop.config.js --inline --progress --port 3000"

But when I'm running the application, all the scripts that have been built are still referring port 8080

localhost/:9 GET http://localhost:8080/app.css net::ERR_CONNECTION_REFUSED
localhost/:12 GET http://localhost:8080/polyfills.aecdc998b10e42f4da92.js net::ERR_CONNECTION_REFUSED
localhost/:12 GET http://localhost:8080/vendor.aecdc998b10e42f4da92.js net::ERR_CONNECTION_REFUSED

Any idea?

1 Answer

Ryan Dudley
Ryan Dudley
Treehouse Project Reviewer

Hope you are having a good day so far, hopefully I can be of some help!

I believe to change the port that the webpack-dev-server runs on, you have to add the devServer config object to your webpack.config.js.

So, somewhere in your webpack-config-js, add something like the following and it should change the port that the dev-server is running on :

devServer: {
  port: 3000
},

Then when you run the webpack-dev-server via npm start (or whatever command you have specified to run webpack-dev-server in your package.json; so 'serve' in this case), it should start up on port 3000.

Hopefully this was able to resolve your issue, and if you have any further questions don't hesitate to ask!

Hi Ryan,

many thanks for the hint!