localhost:4200 not working for my angular app - node.js

Till yesterday, everything was working good. Using cmd, I type ng serve, go to my browser type localhost:4200 and my website fires up.
Suddenly today, the localhost is not responding. The ng serve is working properly.
Output after typing ng-serve-
10% building 3/3 modules 0 activei 「wds」: Project is running at http://localhost:4200/webpack-dev-server/
i 「wds」: webpack output is served from /
i 「wds」: 404s will fallback to //index.html
chunk {main} main.js, main.js.map (main) 47.8 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 264 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 9.7 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 3.81 MB [initial] [rendered]
Date: 2019-09-05T04:20:41.402Z - Hash: a7331d4e748902ef88b7 - Time: 19033ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
I tried different browsers, tried reinstalling angular, still the problem persists.
The message that I get on my browser is - This site can't be reached.

You can try changing your host and your port, something like this:
ng serve --host 0.0.0.0 --port 5000
Maybe it will help...

With ng serve instead of opening the URL with http://localhost:4200 open with http://0.0.0.0:4200 .

Ok I found the problem.
After Windows Update, the Firewall Settings were messed up. I restored the default settings and now it's working fine.
Moral of the Story: Use Linux!

Before starting your app making every time first compile.
Steps.
Go to your file location in CMS.
And type ng serve and wait.
Then go to localhost:4200

Related

localhost:3000 doesn't display anything when run in Docker container [duplicate]

This question already has answers here:
Docker container doesn't publish port as expected when started with webpack-dev-server
(2 answers)
Closed 6 months ago.
I’m trying to dockerize a MERN stack app, here’s the code in my client directory Dockerfile
FROM node:16
WORKDIR /usr/src/douban
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
ENV NODE_ENV=development
CMD ["npm","start"]
I build the image and run the container using the command
$ docker build -t douban-client .
$ docker run -p 3000:3000 -d douban-client
I use ‘docker ps’ and ‘docker logs’ command to test the running container, the output shows it runs successfully. However, when I open localhost:3000, it shows ‘This page isn’t working. localhost didn’t send any data.’
Can anyone tell me what’s wrong? really appreciate your help.
run docker ps:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8cde2b46c18a douban-client "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:3000->3000/tcp heuristic_wescoff
run docker logs:
> my-app#0.1.0 start
> cross-env NODE_ENV=development webpack-dev-server --config ./build/config/webpack.dev.js
ℹ Compiling STARTING
✔ STARTING: Compiled successfully in 9.08s
assets by path public/ 42.3 KiB
assets by path public/*.png 19.3 KiB
asset public/follower.png 8.86 KiB [emitted] [from: public/follower.png] [copied]
asset public/systemprompt.png 6.16 KiB [emitted] [from: public/systemprompt.png] [copied]
asset public/message.png 4.32 KiB [emitted] [from: public/message.png] [copied]
asset public/defaultAvatar.webp 17 KiB [emitted] [from: public/defaultAvatar.webp] [copied]
asset public/favicon.ico 3.5 KiB [emitted] [from: public/favicon.ico] [copied]
asset public/index.html 2.1 KiB [emitted] [from: public/index.html] [copied]
asset public/manifest.json 322 bytes [emitted] [from: public/manifest.json] [copied]
<w> [webpack-dev-server] "hot: true" automatically applies HMR plugin, you don't have to add it manually to your webpack configuration.
<i> [webpack-dev-server] Project is running at:
<i> [webpack-dev-server] Loopback: http://127.0.0.1:3000/
<i> [webpack-dev-server] Content not from webpack is served from '/usr/src/douban/public' directory
<i> [webpack-dev-server] 404s will fallback to '/'
asset public/robots.txt 67 bytes [emitted] [from: public/robots.txt] [copied]
assets by path js/*.js 11.1 MiB
asset js/app.js 11.1 MiB [emitted] (name: app)
asset js/node_modules_web-vitals_dist_web-vitals_js.js 13.1 KiB [emitted]
asset index.html 2.14 KiB [emitted]
orphan modules 905 KiB [orphan] 553 modules
runtime modules 30.1 KiB 18 modules
modules by path ./node_modules/ 3.32 MiB 751 modules
modules by path ./src/ 247 KiB
modules by path ./src/views/ 118 KiB 26 modules
modules by path ./src/components/ 47.9 KiB 20 modules
modules by path ./src/app/ 14.4 KiB 8 modules
modules by path ./src/api/*.ts 43.3 KiB 8 modules
modules by path ./src/lib/ 8.37 KiB 7 modules
modules by path ./src/styles/ 4.21 KiB 4 modules
modules by path ./src/routes/*.tsx 7.03 KiB 3 modules
modules by path ./src/*.tsx 1.42 KiB 2 modules
./src/reportWebVitals.ts 517 bytes [built] [code generated]
./src/providers/index.tsx 1.49 KiB [built] [code generated]
webpack 5.74.0 compiled successfully in 9067 ms
Type-checking in progress...
ℹ Compiling STARTING
✔ STARTING: Compiled successfully in 659.51ms
assets by status 55.5 KiB [cached] 9 assets
assets by status 11.1 MiB [emitted]
assets by chunk 11.1 MiB (name: app)
asset js/app.js 11.1 MiB [emitted] (name: app)
asset app.6e417c1d373746eb7ad3.hot-update.js 847 bytes [emitted] [immutable] [hmr] (name: app)
asset index.html 2.14 KiB [emitted]
asset app.6e417c1d373746eb7ad3.hot-update.json 27 bytes [emitted] [immutable] [hmr]
Entrypoint app 11.1 MiB = js/app.js 11.1 MiB app.6e417c1d373746eb7ad3.hot-update.js 847 bytes
cached modules 4.44 MiB [cached] 1384 modules
runtime modules 30.1 KiB 18 modules
webpack 5.74.0 compiled successfully in 661 ms
Type-checking in progress...
No errors found.
No errors found.
I use webpack-dev-server, and I expose the host and post in the webpack config. My npm start script looks like this
"start": "cross-env NODE_ENV=development webpack-dev-server --config ./build/config/webpack.dev.js"
webpack.dev.js:
const webpack = require("webpack")
const { merge } = require("webpack-merge")
const common = require("./webpack.common")
const SERVER_HOST = "127.0.0.1"
const SERVER_PORT = 3000
module.exports = merge(common, {
mode: "development",
devtool: "eval-source-map",
devServer: {
host: SERVER_HOST,
port: SERVER_PORT,
compress: true,
open: true,
hot: true,
historyApiFallback: {
index: "/",
},
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization",
},
},
plugins: [new webpack.HotModuleReplacementPlugin()],
})
It looks like you're using webpack-dev-server:
<i> [webpack-dev-server] Loopback: http://127.0.0.1:3000/
By default, the dev server runs on 127.0.0.1 to enable accessing localhost:XXXX on browsers. But this does not expose the content outside of a Docker container. You need the dev server to use 0.0.0.0 in order to be reachable from outside the container.
Depending on how you start your dev server, modify it to set the host to 0.0.0.0. Example:
"start": "webpack-dev-server --host 0.0.0.0 --port 3000"
Edit:
Or you can keep your npm start script the same but update your webpack.dev.js:
const SERVER_HOST = "0.0.0.0"
Source: https://dev.to/ku6ryo/run-webpackdevserver-in-docker-1mg5

new angular 8 application return http 400

I am facing a strange error. I am creating new clean angular 8 app and successfully built code but try to open application at localhost:4200 (or any port I changed to) app return http 400
I have added build info. Uninstall node js and re-install it and still same
10% building 3/3 modules 0 activei 「wds」: Project is running at http://localhost:4200/webpack-dev-server/
i 「wds」: webpack output is served from /
i 「wds」: 404s will fallback to //index.html
chunk {main} main.js, main.js.map (main) 49.4 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 264 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 10.1 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 4.08 MB [initial] [rendered]
Date: 2019-10-21T10:00:41.976Z - Hash: 8acb354556900c2f8710 - Time: 9192ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
i 「wdm」: Compiled successfully.
May be there is something in your server.js file in nodejs app. Are you allowing requests from all urls ? You need to enable Cross Origin Resource Sharing.

How to connect to angular, nodejs http://localhost:4200 in google chrome

I am following the tutorial from https://angular.io/cli, but i am unable to connect to http://localhost:4200 after using the command ng serve from my command prompt.
The page returned the following error: This site can’t provide a secure connection, ERR_SSL_PROTOCOL_ERROR
The project is compiled successfully
I had tried allowing nodejs.exe and chrome.exe to in firewall
I disabled the Proxy Server From the (Settings -> Advance Settings -> Open Proxy Settings -> LAN settings)
I tried telnet cmd>telnet localhost 4200 (successful)
I tried connecting from internet explorer, it worked but there is no content in the webpage.
The following are executed within the windows command prompt following the tutorial:
C:\Users\Ufinity\Desktop\test-angular>ng serve
10% building 3/3 modules 0 activei 「wds」: Project is running at http://localhost:4200/webpack-dev-server/
i 「wds」: webpack output is served from /
i 「wds」: 404s will fallback to //index.html
chunk {main} main.js, main.js.map (main) 49.4 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 264 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 9.71 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 4.08 MB [initial] [rendered]
Date: 2019-09-05T09:55:54.613Z - Hash: 2c73ac9786af94e810bc - Time: 10587ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
i 「wdm」: Compiled successfully.
I should be able to connect to http://localhost:4200 and the page should display a welcome to test-angular page.
Solution 1: Use incognito google chrome to go to http://localhost:4200
Solution 2: Make sure you are not connected to any VPN:
Go to developer tools Chrome 3 dots > More tools > Developer tools
Right click on the refresh button > select > Empty Cache and Hard Reload
Then type http://localhost:4200
Go to developer tools
Empty cache and hard reload
Enter http://localhost:4200
Check baseUrl: 'http://localhost:4200/'
in protractor.config.js file

node_modules and Angular issues

I cannot piece the reason for my errors:
PS C:\Users\Zakariah Siyaji\Desktop\AngularAdmin> ng serve
** Angular Live Development Server is listening on localhost: 4200, open your browser on http://localhost:4200/ **
Date: 2018-08-18T23:32:59.066Z Hash: 8230d7de0b0765e109df Time: 9191ms
chunk {main} main.js, main.js.map (main) 2.06 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 691 bytes
[initial] [rendered] chunk {runtime} runtime.js, runtime.js.map
(runtime) 5.4 kB [entry] [rendered] chunk {styles} styles.js,
styles.js.map (styles) 28.3 kB [initial] [rendered] chunk {vendor}
vendor.js, vendor.js.map (vendor) 325 kB [initial] [rendered]
ERROR in
node_modules/#angular/material/stepper/typings/stepper.d.ts(26,22):
error TS2415: Class 'MatStepper' incorrectly extends base class
'CdkStepper'. Types of property '_stepHeader' are incompatible.
Type 'QueryList' is not assignable to type 'QueryList'.
Type 'ElementRef' is not assignable to type 'FocusableOption'.
Property 'focus' is missing in type 'ElementRef'.
i 「wdm」: Failed to compile.
I deleted node_modules, I did npm install and npm update but neither
of those options fixed the issue. The code is flawless, it is simply
an issue related to node_modules and different packages.

Running an Angular2 app on EC2

I'd like to run a basic Angular 2 app on an Ubuntu EC2 instance.
In my case, I installed Angular CLI, and created a new site in /var/www
ng new test
then
ng serve --port 8080
It looks like my basic Angular2 app is running fine
** NG Live Development Server is listening on localhost:8080, open your browser on http://localhost:8080 **
Hash: e0094cf33de0e6b8f264
Time: 9090ms
chunk {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 171 kB {4} [initial] [rendered]
chunk {1} main.bundle.js, main.bundle.js.map (main) 5.28 kB {3} [initial] [rendered]
chunk {2} styles.bundle.js, styles.bundle.js.map (styles) 10.5 kB {4} [initial] [rendered]
chunk {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 2.18 MB [initial] [rendered]
chunk {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
webpack: Compiled successfully.
I know port 8080 is open in my security groups, because I just ran a basic Node JS app a few minutes ago in /var/www. When I try to go to http://[Public DNS]:8080, Safari says it can't connect. There's also nothing in my apache logs.
Turns out the real issue is this:
https://github.com/angular/angular-cli/issues/6070
I've tried editing the server.js file and running with the --publicHost option, but those aren't working. I'm using non CLI Angular with the default port 3000 and that's working on EC2 (after adding the security group settings).

Resources