Default application port change
Friends I wanted to change the default port of the sample app that I was running.
I started exploring the options for it !! I was bored with the default port 3000.
Approach: search for possible config files however this was too time consuming
1. First Method
1. I modified the default-config.js
a. This file is located at /node_modules\lite-server\node_modules\browser-sync\lib\default-config.js
Below is the entry in the file.
proxy: false,
/**
* @property port
* @type Number
* @default 3000
*/
port: 3000,
// modify this to say 4001
b. Save the file
c. Restart the application to see that the application now runs at the new port.
d. Stop the application by CTRL + C
e. npm start
2. Second method.
a. Create a new file bs-config.json in your application folder
b. Below is the sample content of it
{
"port": 7080,
"files": ["./**/*.{html,htm,css,js}"],
"server": { "baseDir": "." }
}
c. Restart the application
d. Stop the application by CTRL + C
e. npm start
Interesting point to note here is that now the application will detect the config file and load the application in the new port mentioned here
Below is snapshot of the application.
c:\Angular-Quarters>npm start
> angular2-quickstart@1.0.0 start c:\Angular-Quarters
> tsc && concurrently "npm run tsc:w" "npm run lite"
[1]
[1] > angular2-quickstart@1.0.0 lite c:\Angular-Quarters
[1] > lite-server
[1]
[0]
[0] > angular2-quickstart@1.0.0 tsc:w c:\Angular-Quarters
[0] > tsc -w
[0]
[1] ** browser-sync config **
[1] { injectChanges: false,
[1] files: [ './**/*.{html,htm,css,js}' ],
[1] watchOptions: { ignored: 'node_modules' },
[1] server: { baseDir: '.', middleware: [ [Function], [Function] ] },
[1] port: 7080 }
[0] 10:01:25 PM - Compilation complete. Watching for file changes.
[1] [BS] Access URLs:
[1] ------------------------------------
[1] Local: http://localhost:7080
[1] External: http://192.168.0.3:7080
[1] ------------------------------------
[1] UI: http://localhost:3001
[1] UI External: http://192.168.0.3:3001
[1] ------------------------------------
[1] [BS] Serving files from: .
[1] [BS] Watching files...
[1] 16.07.28 22:01:33 200 GET /index.html
[1] 16.07.28 22:01:33 200 GET /node_modules/core-js/client/shim.min.js
[1] 16.07.28 22:01:33 200 GET /systemjs.config.js
[1] 16.07.28 22:01:33 200 GET /styles.css
[1] 16.07.28 22:01:33 200 GET /node_modules/reflect-metadata/Reflect.js
[1] 16.07.28 22:01:33 200 GET /node_modules/zone.js/dist/zone.js
[1] 16.07.28 22:01:33 200 GET /node_modules/systemjs/dist/system.src.js
[1] 16.07.28 22:01:34 200 GET /app/main.js
[1] 16.07.28 22:01:34 200 GET /node_modules/@angular/platform-browser-dynamic//b
undles/platform-browser-dynamic.umd.js
[1] 16.07.28 22:01:34 200 GET /app/app.component.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/Subject.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/observable/PromiseObservable.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/operator/toPromise.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/Observable.js
[1] 16.07.28 22:01:34 200 GET /node_modules/@angular/common//bundles/common.umd.
js
[1] 16.07.28 22:01:34 200 GET /node_modules/@angular/platform-browser//bundles/p
latform-browser.umd.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/Subscriber.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/Subscription.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/SubjectSubscription.js
[1] 16.07.28 22:01:34 200 GET /node_modules/@angular/core//bundles/core.umd.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/symbol/rxSubscriber.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/util/throwError.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/util/ObjectUnsubscribedError.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/util/root.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/symbol/observable.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/util/toSubscriber.js
[1] 16.07.28 22:01:34 200 GET /node_modules/@angular/compiler//bundles/compiler.
umd.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/Observer.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/util/isFunction.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/util/isArray.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/util/tryCatch.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/util/isObject.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/util/errorObject.js
[1] 16.07.28 22:01:34 200 GET /node_modules/rxjs/util/UnsubscriptionError.js
[1] 16.07.28 22:01:34 404 GET /favicon.ico
[1] 16.07.28 22:01:38 304 GET /index.html
[1] 16.07.28 22:01:38 304 GET /styles.css
[1] 16.07.28 22:01:38 304 GET /node_modules/core-js/client/shim.min.js
[1] 16.07.28 22:01:38 304 GET /node_modules/zone.js/dist/zone.js
[1] 16.07.28 22:01:38 304 GET /node_modules/systemjs/dist/system.src.js
[1] 16.07.28 22:01:38 304 GET /node_modules/reflect-metadata/Reflect.js
[1] 16.07.28 22:01:38 304 GET /systemjs.config.js
[1] 16.07.28 22:01:38 304 GET /app/main.js
[1] 16.07.28 22:01:38 304 GET /node_modules/@angular/platform-browser-dynamic//b
undles/platform-browser-dynamic.umd.js
[1] 16.07.28 22:01:38 304 GET /app/app.component.js
[1] 16.07.28 22:01:38 304 GET /node_modules/@angular/common//bundles/common.umd.
js
[1] 16.07.28 22:01:38 304 GET /node_modules/@angular/compiler//bundles/compiler.
umd.js
[1] 16.07.28 22:01:38 304 GET /node_modules/@angular/core//bundles/core.umd.js
[1] 16.07.28 22:01:38 304 GET /node_modules/@angular/platform-browser//bundles/p
latform-browser.umd.js
[1] 16.07.28 22:01:38 304 GET /node_modules/rxjs/observable/PromiseObservable.js
[1] 16.07.28 22:01:38 304 GET /node_modules/rxjs/Subject.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/Observable.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/operator/toPromise.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/util/root.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/Subscriber.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/Subscription.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/SubjectSubscription.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/symbol/rxSubscriber.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/util/ObjectUnsubscribedError.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/symbol/observable.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/util/toSubscriber.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/util/throwError.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/util/isFunction.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/Observer.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/util/isArray.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/util/isObject.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/util/tryCatch.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/util/errorObject.js
[1] 16.07.28 22:01:39 304 GET /node_modules/rxjs/util/UnsubscriptionError.js
Note:
If you observe the pattern in which the node starts the application like the below, you'll see that the application looks for the bs-config.json however in the first case it didn't find it.
Once this was created in the port modifier exercise, the new port was picked up.
c:\Angular-Quarters>npm start
> angular2-quickstart@1.0.0 start c:\Angular-Quarters
> tsc && concurrently "npm run tsc:w" "npm run lite"
[0]
[0] > angular2-quickstart@1.0.0 tsc:w c:\Angular-Quarters
[0] > tsc -w
[0]
[1]
[1] > angular2-quickstart@1.0.0 lite c:\Angular-Quarters
[1] > lite-server
[1]
[1] Did not detect a `bs-config.json` or `bs-config.js` override file. Using lit
e-server defaults...
[1] ** browser-sync config **
[1] { injectChanges: false,
[1] files: [ './**/*.{html,htm,css,js}' ],
[1] watchOptions: { ignored: 'node_modules' },
[1] server: { baseDir: './', middleware: [ [Function], [Function] ] } }
[0] 9:56:42 PM - Compilation complete. Watching for file changes.
[1] [BS] Access URLs:
[1] ------------------------------------
[1] Local: http://localhost:3000
[1] External: http://192.168.0.3:3000
[1] ------------------------------------
[1] UI: http://localhost:3001
[1] UI External: http://192.168.0.3:3001
[1] ------------------------------------
[1] [BS] Serving files from: ./
[1] [BS] Watching files...
[1] 16.07.28 21:56:55 304 GET /index.html
[1] 16.07.28 21:56:55 304 GET /styles.css
[1] 16.07.28 21:56:55 304 GET /node_modules/core-js/client/shim.min.js
[1] 16.07.28 21:56:55 304 GET /node_modules/zone.js/dist/zone.js
[1] 16.07.28 21:56:55 304 GET /node_modules/reflect-metadata/Reflect.js
[1] 16.07.28 21:56:55 304 GET /systemjs.config.js
[1] 16.07.28 21:56:55 304 GET /node_modules/systemjs/dist/system.src.js
[1] 16.07.28 21:56:55 200 GET /app/main.js
[1] 16.07.28 21:56:55 304 GET /node_modules/@angular/platform-browser-dynamic//b
undles/platform-browser-dynamic.umd.js
[1] 16.07.28 21:56:55 200 GET /app/app.component.js
[1] 16.07.28 21:56:55 304 GET /node_modules/@angular/common//bundles/common.umd.
js
[1] 16.07.28 21:56:55 304 GET /node_modules/@angular/core//bundles/core.umd.js
[1] 16.07.28 21:56:55 304 GET /node_modules/@angular/platform-browser//bundles/p
latform-browser.umd.js
[1] 16.07.28 21:56:55 304 GET /node_modules/@angular/compiler//bundles/compiler.
Now enjoy playing with the port numbers and run application on your favorite port !!