Embarking on your first software development project can be a daunting experience, especially when it comes to navigating the world of serverless applications and cloud deployments. If you've been seeking a beginner-friendly guide to deploying your first Node.js application on Google Cloud, look no further. This article is designed with you in mind - breaking down each step of the process in a simple, easy-to-understand way. This comprehensive guide will help you get your serverless application off the ground. Let's dive in and start exploring the power of cloud computing!
Deploying a serverless Node.js application to Google Cloud involves several key steps:
Firstly, you'll need a Google Cloud account. If you don't have one already, head over to
Then you should click on “My Project“
(image 2) and then click on “NEW PROJECT“
(image 3) button.
On this page, you will see all existing projects that you have access to see. If you are working on an organization and have an account on it, you will see all projects of the current company.
On the project settings, you can set up a name and an organization, if exists (Image 4).
Don’t forget to select your current project on the list. Finally, you will see “Your project name“
on the main Google Console page.
To deploy your Node.js application, you'll need to install Google Cloud SDK. You can download it
gcloud auth login
This will open a new browser window where you can log in with your Google account.
gcloud config set project your-project-id
Writing a simple nodejs project I have detailed explained in my previous article. The main project code will be:
const http = require('http');
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(8080, '0.0.0.0', () => {
console.log('Server running at http://0.0.0.0:8080/');
});
A package.js will be:
{
"name": "hackernoon",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"keywords": [],
"author": "",
"license": "ISC"
}
Also, you need to create a app.yaml
file for gcloud and save it in the project folder. Put this code:
runtime: nodejs18
service: default
Cloud Functions now requires an active billing account. You will need to add one, otherwise, you will not be able to deploy your nodejs app on GCP. Enable Cloud Functions, after adding billing info, your Google account will have free 300 creds on it.
Run cmd.exe
from the project folder and execute this command:
gcloud app create
This command will enable the App Engine on your current project. You should choose a location after the gcloud will do everything for you.
Creating App Engine application in project [ivory-studio-387214] and region [europe-central2]....done.
Success! The app is now created. Please use `gcloud app deploy` to deploy your first app.
Finally, execute this deploy command:
gcloud app deploy --quiet app.yaml --promote --stop-previous-version --version main-v1
You will see the message that your nodejs has successfully deployed.
On your console, you will see the deployed information:
descriptor: [C:\Users\Nuriq\Desktop\Hackernoon\app.yaml]
source: [C:\Users\Nuriq\Desktop\Hackernoon]
target project: [ivory-studio-387214]
target service: [default]
target version: [main-v1]
target url: [https://ivory-studio-387214.lm.r.appspot.com]
target service account: [App Engine default service account]
Now, you can access your app via target url:
https://ivory-studio-387214.lm.r.appspot.com
Congratulations on taking your first steps into the world of serverless applications and Google Cloud deployment. In this guide, you've learned how to set up your Google Cloud account, install and configure Google Cloud SDK, write a Node.js function, and deploy and test it on Google Cloud. This is a significant milestone in your software development journey!
However, this is just the tip of the iceberg. The vast expanse of cloud services, along with the versatility of Node.js, opens a world of endless possibilities. It allows you to build scalable, efficient, and powerful applications.
Thank you for taking the time to follow along with this guide. We look forward to sharing more exciting aspects of software development in our future posts. Until then, keep coding, and see you next week!