How to deploy nodejs app in google cloud?

I am trying to deploy a nodejs application in the google cloud, I posted some questions about the problems I was getting and how to fix them. Let me illustrate my efforts ...

problem 1) I tried to run a tutorial application hello world deployment. When I entered the deployment command,

$ gcloud preview app deploy app.yaml --set-default 

This gave me a message stating that managed vms are not available for your application region. I contacted someone from Google, a representative of Google technical support, said that his name was Ling, and he said that he “did not know that managed vms are not supported in India,” and he wanted me to indicate where I found this information. So I sent him, pay attention to one of the answers. OK .....

problem 2) So, I'm stuck, did not know what to do. I searched “how to deploy the nodejs application in the Google Cloud” and found a video in which the Google developer told me that there are “two main ways to run the application in the cloud, infrastructure as a service and platform as a service”. Running it on an application platform was a platform as a service, and it was not on the list, so I went with my only remaining option. There is a textbook, a textbook on the bookshelf , as well as google, and the last part describes how to run the application on a computing engine. I tried to go through the tutorial, but when I entered the command

 git push cloud 7-gce:master 

in order to push my code to the repository, he asks me about my username and password. He never mentioned that in the textbook I do not know what to introduce. I found this question , but I'm not sure if this applies to my situation. So, I got acquainted with some tutorials suggested by Zachary Newman, and I couldn’t follow the tutorial where they use ubuntu, because when they tell you the hello.js file, this is really strange, because I had to ssh into the ubuntu vm image, which I created and everything was very slow, I am not familiar with the commands on linux, so I had to look for “save and exit” after creating the hello.js file. I got a “web server” to run, this is a reverse proxy nginx server, but since I don’t know what APP_PRIVATE_IP_ADDRESS is, when I accessed the page, I could see the nginx page, but not the message “hello world” should be displayed. Please see the Prerequisites heading to find out what my tutorial taught. OK ....

problem 3) In the Google developer console after logging in there is a navigation section on the left, there is a link to "Cloud Launcher", There I found a link for creating a virtual machine with installed nodejs created by Bitnami. I clicked it and my vm was running, I went to the external IP address provided, and saw the “Congratulations” page (ugh ...) in Bits. I did not know what to do next, so I posted another question. The bitnami developer told me that I need to copy the files to a remote repository, create the configuration files, and then you must include this configuration in the Apache configuration to serve the application. "How?!?! He just posted a link to the bitnami wiki page . I used filezilla to connect to my vm, and I tried to load the application files into vm. I managed to load everything except the node modules (they took too long to load, and for some reason the ftp client continued to lose connection with the server after 10 minutes or so). So I thought th I will simply ssh in the instance and try to install npm my addiction. But it gave me more errors ...

problem 4) I do not know why this post was suspended, but I found this . I cannot find the exact page right now, but I read somewhere in google docs that we cannot use ssh in the instance as root / administrator by design, and that we have to do some advanced configuration in order to be able to do this. The PROBLEM is that I can’t install the dependencies if I don’t go down as an administrator ...: '(So I just downloaded my node modules with filezilla. Everything looks fine, I ssh in my instance and I cd in application directory and enter the command

 node app.js 

and almost as if mocking me, he turns off the logs "connected to mongo ...." and "Listening on port 3000 .....". I'm so excited, I think it works .....

problem 4) The server never started, I think it could not connect to the mongodb database (another instance) in which I was working, it was a command to connect to the mongodb instance in the app.js file

 mongoose.connect('mongodb://****/myappdatabase'); 

where **** indicates the external IP address of my mongodb instances. After about 5 minutes, I get an error message in the ssh browser

 Error: connect ETIMEDOUT ****:27017 

BUT WHO TIME TO READ ALL THIS RIGHT?

I am not a developer, I do not have much programming experience (close to zero). I am a lover. I took a book on programming in stephen g. kochan about 5 or 6 months ago, and since then I just read textbooks on the Internet, programming in a java book and some reference materials. I wanted to create a website.

I learned some html, css, javascript and jquery outside of w3schools and went through several tutorials on creating a basic node server and serving some html pages, which is literally my whole application. That is all I want.

I used the express framework for node and mongoose to connect to my mongodb working locally. Socket.io for a small number of networks. I created a website for fun, and I would really like to post it and share it with friends, I did it this far, it would be really awkward to quit now because I can not host the site. By the way, I went a lot more than what I wrote on this subject.

Now I would really appreciate some help, even for what I need to know, maybe the books I should read, or the documentation I have to go through to get a better understanding of website hosting, would be great. I am going to offer this question for generosity in 2 days, but until then, if someone who has gone through this and would like to help without personal gain will save my life. I'm going for about 4 days with no luck. Thank you and let me know if there is anything you would like to know about my application. I mean seriously how much this can be, I'm doing something (or all) terribly wrong.

+6
source share
1 answer

Wow dude. I thought about tagging this, but you seem to sincerely want to learn how to program and need help. And experienced coders training novice coders is what this site is about. So here we go.

First of all, Linux is your friend. Get to know him. Use it. I do not use Ubuntu, but you need to. Use 14.04 because it is a forgiving disto and comes packaged with the things you need when you're just learning.

Time to resolve your questions:

Problem 1: you are using the gcloud preview product. This is awesome, but not for beginners, because you do not know what you are doing. Just stand up to the n1 Ubuntu instance and download it. There are no bells. No whistles. Learn Linux Ubuntu with the same passion that you taught yourself how to program a website.

Problem 2: Do not use git. I use git every day, and it's awesome, but you have a long way to go, and git is ridiculous. Take your workspace, tar / gzip and just ssh the whole shebang to cloud. Then unzip it and you will have all your code right on your server. Caution: never do it professionally. But for someone who is just learning ... little bites dude ... little bites.

Problem 3: Do not use pre-created Bitnami images. This makes it impossible for you to learn how to do it from scratch, and it is an invaluable experience. Here are two commands you should learn:

 apt-get update apt-get install <insert thing you want to install> 

Here it is. Not rocket science, and you will discover the power of package management on Linux.

Problem 4: You think too much about this. Truly learn apt-get . He gets to you, you curse yourself for not using it before. apt-get node. apt-get mongo. And slam it all on one copy. Is this what I do professionally? Of course not. But it's all about babies, when you combine dev-ops with programming, and you need to do these steps.

Corrections: You wanted someone to recommend a book or website or guide. All you need to know is already on Ubuntu. They are called man pages. Its a brief guide. You can buy all the books in the world from Amazon and watch endless youtube pages. This is not comparable to just man ing commands. You have to trust me.

In short: just create an instance of Ubuntu. tar and gzip all your code and scp into your instance. Learn apt-get , and for real you are set up. You will completely destroy your instance many times. So just delete it, recreate and continue. Each time you will be smarter and smarter than before. I constantly train novice developers. You have to start small and work. In the end, you will understand why you want to use git. Why do you want to scale. Why the LXC is awesome. Why a managed instance of GCEs and virtual machines is a crazy ballerina, and why your deployment scenarios are best practice. But first you need to understand how to instantiate and get your code there in some way. You will grow from there. Good luck buddy.

+8
source

All Articles