Node.js Google DOCS API Example to Create,Read & Delete Word Documents in Browser Using Javascript Full Project For Beginners

 

 

npm i google-documents-api

 

 

Usage

  1. Install module
    npm install google-documents-api
  2. Obtain service auth credentials. Follow steps 2-7 in google-sheets-api usage instructions.
  3. Authorize your service email address (obtained in previous step) to read the document.
  4. Collect the document id from URL. https://docs.google.com/document/d/THIS_IS_THE_DOCUMENT_ID/edit

 

 

index.js

 

 

var fs = require('fs');
var Documents = require('google-documents-api');
 
var documentId = 'your-document-id';
var serviceEmail = 'generated-by-dev-console@developer.gserviceaccount.com';
var serviceKey = fs.readFileSync('path/to/your/sheets.pem').toString();
 
var docs = new Documents({ email: serviceEmail, key: serviceKey });
 
docs.getDocumentHtml(documentId).then(function(htmlContent) {
  console.log(htmlContent);
})
.catch(function(err){
  console.error(err, 'Failed to read document');
});

Leave a Reply