1.1.2 • Public • Published


    Travis CI FOSSA Status

    Library to operate with Google Drive API v3 from Node.js, using system user tokens or personal keys

    This library is heavily inspired on theozero's' google-spreadsheet. No, I mean, really inspired. As in blatantly copied. The only difference being his library is to operate with google spreadsheets and this one is to interact with google drive.

    So, basically, you can operate in two ways. You either use Google Oauth and manually enter your credentials everytime, or use a Service Account and forget about further authentications.

    How to create a Service Account

    (the following is taken from google-spreadsheet docs)

    1. Go to the Google Developers Console
    2. Select your project or create a new one (and then select it)
    3. Enable the Drive API for your project
    • In the sidebar on the left, expand APIs & auth > APIs
    • Search for "drive"
    • Click on "Drive API"
    • click the blue "Enable API" button
    1. Create a service account for your project
    • In the sidebar on the left, expand APIs & auth > Credentials
    • Click blue "Add credentials" button
    • Select the "Service account" option
    • Select "Furnish a new private key" checkbox
    • Select the "JSON" key type option
    • Click blue "Create" button
    • your JSON key file is generated and downloaded to your machine (it is the only copy!)
    • note your service account's email address (also available in the JSON key file)
    1. Share the doc (or docs) with your service account using the email noted above

    Example usage:

    Let's say you stored your user credentials in a file called my_credentials.json. And you gave permission to the service account's email address over a folder in your Google Drive whose id is 1bibD4HDZVbqOPq882YSDTmZlI06fZvLU. So you would do:

    const YOUR_ROOT_FOLDER = '1bibD4HDZVbqOPq882YSDTmZlI06fZvLU',
        PATH_TO_CREDENTIALS = path.resolve(`${__dirname}/my_credentials.json`);
    // Let's wrap everything in an async function to use await sugar
    async function ExampleOperations() {
        const creds_service_user = require(PATH_TO_CREDENTIALS);
        const googleDriveInstance = new NodeGoogleDrive({
        let gdrive = await googleDriveInstance.useServiceAccountAuth(
        // List Folders under the root folder
        let folderResponse = await googleDriveInstance.listFolders(
        console.log({ folders: folderResponse.folders });
        // Create a folder under your root folder
        let newFolder = { name: 'folder_example' + },
            createFolderResponse = await googleDriveInstance.createFolder(
        debug(`Created folder ${} with id ${}`);
        // List files under your root folder.
        let listFilesResponse = await googleDriveInstance.listFiles(
        for (let file of listFilesResponse.files) {
            debug({ file });

    See API for a description of available methods.


    FOSSA Status


    npm i node-google-drive

    DownloadsWeekly Downloads






    Unpacked Size

    39.1 kB

    Total Files


    Last publish


    • amenadiel