Académique Documents
Professionnel Documents
Culture Documents
Images haven’t loaded yet. Please exit printing, wait for images to load, and try to print again.
Agira Technologies Follow
Leading web development company in India. Expert in creating web application( Ruby on Rails,
Golang, Laravel, Symfony, PHP, MEAN Stack) & mobile app development
Aug 16 · 6 min read
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 1/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
Now you can do much more with JavaScript than just making websites
interactive.
Prerequisites
To run this simple example, all you’ll need is
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 2/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
Step 1.2: To enable the spreadsheet API, please check the screenshot.
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 3/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
Step 1.3: In search box, type the word google sheet and click the card to
enable the spreadsheet API
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 4/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
Step 1.4: Once the google spreadsheet API enables, then you need to
create credentials, Use this URL link to create a credentials
Step 1.5: then click the “create credentials” from the dropdown and
select the OAuth client ID.
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 5/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
Step 1.6: Select the checkbox “other” option and click the create.
Step 1.7: then download the credentials le and we can use this le in
our sample code.
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 6/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 7/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
var fs = require('fs');
var SCOPES =
['https://www.googleapis.com/auth/spreadsheets'];
function storeToken(token) {
try {
fs.mkdirSync(TOKEN_DIR);
} catch (err) {
throw err;
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 8/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
fs.writeFile(TOKEN_PATH, JSON.stringify(token));
access_type: 'offline',
scope: SCOPES
});
var rl = readline.createInterface({
input: process.stdin,
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 9/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
output: process.stdout
});
rl.close();
if (err) {
return;
oauth2Client.credentials = token;
storeToken(token);
callback(oauth2Client);
});
});
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 10/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
if (err) {
getNewToken(oauth2Client, callback);
} else {
oauth2Client.credentials = JSON.parse(token);
callback(oauth2Client);
});
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 11/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
function listMajors(auth) {
var requestInsert = {
auth: auth,
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 12/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
spreadsheetId: SPREADSHEET_ID,
range: range,
valueInputOption: 'RAW',
resource : {
range: range,
'majorDimension': 'ROWS',
'values': [["name","list"]]
}
};
sheets.spreadsheets.values.update(requestInsert,
function(err, response) {
if (err) {
throw err;
});
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 13/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
fs.readFile(SPREADSHEET_JSON_FILE, function
processClientSecrets(err, content) {
if (err) {
return;
authorize(JSON.parse(content), listMajors);
});
create();
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 14/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
function listMajors(auth) {
var request = {
auth: auth,
spreadsheetId: SPREADSHEET_ID,
range: range
};
sheets.spreadsheets.values.get(request, function(err,
response) {
if (err) {
throw err;
console.log(response,' records.');
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 15/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
});
fs.readFile(SPREADSHEET_JSON_FILE, function
processClientSecrets(err, content) {
if (err) {
return;
authorize(JSON.parse(content), listMajors);
});
Read()
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 16/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
function listMajors(auth) {
var deleteRequest = {
auth: auth,
spreadsheetId: process.env.SPREADSHEET_ID,
resource : {
'requests': [
'deleteDimension': {
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 17/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
'range': {
'sheetId': sheetId,
'dimension': 'ROWS',
'startIndex': range,
'endIndex': range+1
]
},
};
sheets.spreadsheets.batchUpdate(deleteRequest, function(err,
response) {
if (err) {console.log(err);}
console.log(response,'Deleted');
});
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 18/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
fs.readFile(SPREADSHEET_JSON_FILE, function
processClientSecrets(err, content) {
if (err) {
return;
authorize(JSON.parse(content), listMajors);
});
delete()
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 19/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
$ node spreadsheet.js
The rst time you run the sample, it will prompt you to authorize
access:
If you have not logged into your Google account, then you will be
prompted to log in. If you are logged into multiple Google accounts,
then you will be asked to select one account to use for the
authorization.
Copy the given code, paste it into the command-line prompt, and press
Enter.
That’s all guys! We done it. Here we used NodeJS and we can also use
“Google App Script” to apply this CRUD operation. If you’re interested
to know then let us know your opinions in comment box, will surely
discuss about it in coming days.
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 20/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
Mad over reading? Then never miss out anything from our blog works,
there you can read about all latest technologies & it’s updates which
would be perfect for your 15 minutes tea break! What else guys hit the
subscribe link and go crazy over learning.
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 21/22
11/16/2018 CRUD operation on Google Spreadsheet using NodeJS – Agira Technologies – Medium
https://medium.com/@agiratech/crud-operation-on-google-spreadsheet-using-nodejs-a0a8dbb58c95 22/22