Node JS web application deployment - node.js

I'm developing my first node js web application with Angular 6 front end.
The app works fine in the local environment, but it doesn't work in Azure web app service.
In my web app service, sample (hello world) node js app runs fine. But when I deploy my application which has Angular front end, it does not work(but pages are loading).
I think server is not running, but I don't know how to fix it. I have followed a lot of documentation, but none of them fixed my problem.
Please help. let me know if you need more info.
I'm getting this error when I request functionalities from server.
GET https://ntest4.azurewebsites.net/logincheck/actualusername/actualpassword 404 (Not Found)
ERROR e {headers: t, status: 404, statusText: "Not Found", url: "https://ntest4.azurewebsites.net/logincheck/actualusername/actualpassword", ok: false, …}
Dist folder structure:

You seems to use the HTML5 History mode, you may need to turn all other access to index.html on the service.
(and when I visit https://ntest4.azurewebsites.net, return no permission.)

Since you are using power-shell to log into your remote instance/service, the whole working environment will be different from your local's.
As I mentioned in the comments, you need to:
first, make sure the node -v is correct, as specific version required; if not, you have to manually install that following the node.js;
second, you need to re-install all required modules under your project folder npm install;
then, you should be able to start your project by ng serve.
Please have a check and let me know if anything goes wrong.
One more trick
You can check whether your server is up by
sudo lsof -i -P -n | grep LISTEN | grep 4200
or
sudo netstat -tulpn | grep LISTEN | grep 4200
in your remote.

Related

I have hosted my Nodejs Application on Amazon AWS. Now it shows 502 bad gateway after some time

I started the server using Command prompt by the command "sudo node server.js"
Then I closed the command prompt.
Now after some time, the website automatically shows 502 bad gateway error.
I had also used the command "sudo node server.js &" but it still not works.
Can you help me find out what could be the possible problem.
Thanks in advance!
The problem is that you app is not running, here is why.
When start the application in the command line, the application is handled by that bash instance. When you close that instance, so does the application.
The solution to this is to use a package like pm2 which will make sure that your application is always running.

Deploying MEAN stack application to Heroku

I am trying to deploy an application I am building with the MEAN stack to Heroku and am having some trouble. I think the issue is with the structure of my application. I have all my server code in a folder called server, which has its own package.json and src folder that contains the actual server code.
Right now I am simply trying to get Heroku to deploy the client side of the application. I am only getting an error... I know that the database and server are not running but I cannot even get past the initial displaying of the app. I have one web dyno set up to run ng serve (npm start) on the app.
If someone would be willing to look at the structure of my application and sees why I am unable to deploy to Heroku without really digging into the code, that would be much appreciated.
Here is the code
Please note that it is on the deploy branch, and this is on purpose. I do not want to push anything to the master until I am sure it is working.
The Angular web server targets localhost:4200 by default. That can be changed with a couple command-line options. --port accepts a port and --host accepts a host IP address.
So you could modify the ng serve script as follows: ng serve --host [host-ip] --port [port-number] --disableHostCheck. That last flag (--disableHostCheck) tells the dev server to bypass host checking when normally ng serve fails on anything except localhost. Terrible idea if meant for anything except private development/testing.
Another issue: Heroku runs off web dynos and from what I understand about them, they use a random port and IP each time. While the random port is stored under the variable $PORT, the IP does not seem to have a similar variable. Web dynos keep that information to themselves.
Heroku does offer this command: heroku local web. It runs your application on localhost:5000. That means ng serve --port 5000 works perfectly with this command. This should tell you how your front-end will run on Heroku. Your angular dev server will function as expected too.
For actual deployment to Heroku, use that express server of yours. Run ng build from your file system and it will spit out an index.html in the dist folder. This file holds your entire front-end application. You can then upload that file into your browser from the server.
For express that usually breaks down into:
app.get('*', function(req, res) {
res.sendFile('path/to/index.html');
});
Hopefully this helps! Let me know if I missed the mark anywhere.

Connecting app to AWS EC2 instance

I'm pretty new to DevOps and I'm trying to set up my Node.js app on a AWS server instance. Steps I've taken:
Set up Elastic IP
Launched EC2 instance with Ubuntu server
Connected IP to instance
Allowed incoming connections on port 3000
SSH'd into the server with a .pem file
Now I'm at the point where I need to get my files uploaded to the server. I've used FileZilla (and like it) in the past to upload files but the initial part was already set up. When I set up the site on FileZilla there is no /var/www folder on the remote site.
Don't know how to connect these dots.
Also not sure what I need to run once I successfully upload the files. I imagine npm install when I'm ssh'd into the server? Most of the tutorials out there only go through the basic instance setup.
Thanks!
You don't need to have /var/www. Also, it's better that you use a version control and a remote repository like Github and then SSH to your EC2 and then clone your repository there.
Then cd into your repo and run npm install and then start your app.
And check.
Once you connect to the EC2 instance then clone your code in there. It not mandatory to be in /var/www/html but, it's best practice to keep it there. Once you clone npm install into your project home directory so all the required packages get installed. Then for running your node application in production you have to run it on service as pm2, supervisor, forever, passenger, etc. You can use any of these services and configured appropriately to run your application on desired port. As with pm2, you can follow this guide, install pm2 Then you can run with the following command w.r.t. your environment, like I want to run my application on port 5555 for production
$ PORT=5555 pm2 start app.js --name API --env production -f
Check the status using pm2 list Now, your application is running on http://server-ip:5555/ But, you won't be typing port number every-time. So, you need to configure the web server in front of your application like apache or nginx which will forward all request to your application running port. You could find the best guide to their home page. Then your application is available at http://server-ip/ You can follow this for single configuration of multiple node apps
Hope this helps.

Debug Node application in CF

We are using Diego version 2.80 and I'm trying to debug node.js application...in this URL there is place which you should install node inspector and expose debug port , my question is there a shorter way to do it ? maybe without having the need to download the node inspector ...
Bluemix provides documentation that will show you the options of how to manage and debug Liberty and Node.js apps:
Managing Liberty and Node.js apps
I would recommend reading this documentation to see what options you want to utilize. Please note some of the options work for both Liberty and Node.js, but others are specific to each runtime.
There is even detailed information regarding the inspector you mention above, but the steps you need to take are dependent on your Node version:
Node.js inspector
Assuming you are using the latest Node.js v6:
in your package.json change your app's start command from something like node app.js to node --inspect app.js
push your app
create a SSH tunnel so you can remotely access the debug port which by default is 9229: cf ssh -N -T -L 9229:127.0.0.1:9229 <appName>
get your chrome-devtools URL from cf logs <appName> --recent and browse to it (it will take a few seconds to load)
I found this guide which solved the issue
https://codeburst.io/an-easy-way-to-debug-node-js-apps-in-cloud-foundry-22f559d44516

How to run `OpenFin Process Manager`

Refer to https://github.com/openfin/process-manager
Based on the README.md, I have done the following steps:
npm install
node server
I am able to see the following message from terminal(windows 7)
$ node server
Express server listening on port 5040
How do I launch the application?
I have tried to point to the localhost:5040 through chrome browser and ONLY see three tabs 'Processes', 'Cache', 'Logs' without any information.
How can I fix the issues?
npm i -g openfin-cli
openfin -l -c http://localhost:5040/app_local.json
The server script is running a local express server that hosts an OpenFin enriched web app so all you need to do it launch it on OpenFin, which in the case above we are doing with the CLI.
You can also use a node module to launch i.e. here

Resources