How to Use the Google Drive API with JavaScript

Node.js, Authentication and Google’s Drive API

Bret Cameron
8 min readJun 3, 2019

Google has a huge collection of APIs, and sooner-or-later in your development career, you’re likely to encounter one or more of them: from Google Maps to Google Calendar, YouTube to Google Analytics, and Gmail to Google Drive — there are APIs for a wide variety of tools in Google’s large product-base.

However, the scale of the documentation and the sheer number of available options can make it difficult for newer developers to get started with these tools. Plus, handling authentication can be tricky: there are multiple options depending on the tools you’re using and the context you’re using them in.

In this article, we’ll look into how to use the Google Drive API with JavaScript. If you want to code along to this article, make sure you have Node.js installed. Then, create a new directory for your project, navigate to it in the terminal and type npm init -y . Finally, create a file called index.js in the root folder of your new project.

Authentication

Before using any Google APIs, we’ll need to get past authentication. Visit console.developers.google.com and select a project or create a new one. Projects are used so that it’s easy to see any API activity and billing for a…

--

--

Bret Cameron

Writer and developer based in London. On Medium, I mainly write about JavaScript, web development and Rust 💻