Build a Simple Microservice Google Review API through Heroku

Code in my App.js that builds the simple Google Review API
Make sure you have installed the required dependencies in your app
const url = `https://{nameOfTheApp}.herokuapp.com/reviews/${ID}`;

Heroku Setup and Deployment

Initial Setup

First, make sure you signed up for an account at Heroku and created a project.

Procfile

Procfile is the file that gives instructions to Heroku on how to run your app.

touch Procfile
web: node app.js

Deployment

Three ways to deploy your code to Heroku

  1. CLI — Command Line Interface
heroku git:remote -a “{nameOfTheApp}”
git push heroku master
heroku open

Config Vars

Very important!!! Don’t forget to add your API Key (the environment variable) onto Heroku through the Settings section.

Finally

After deploying this microservice API to Heroku, just hit the API in your project with the Place ID to get the corresponding review data.

https://{nameOfTheApp}.herokuapp.com/reviews/${ID}
I modified my data structure when I did the screenshot, it should return the result object only in my code.

Optional: Enabling CORS

In order to avoid people using your API across different URLs since you do not want to pay for their services, make sure you add the Access-Control-Allow-Origin in your app.

npm install express corsconst express = require('express');
const cors = require('cors');
const app = express();
app.use(cors());
app.use(cors({
origin: 'http://yourapp.com'
}));

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Hanwen Zhang

Hanwen Zhang

Full-Stack Software Engineer at a Healthcare Tech Company | Document My Coding Journey | Improve My Knowledge | Share Coding Concepts in a Simple Way