I am really new to Node and Express, for this project I was trying to post values from the node server to google Sheets which is working. The only issue I am facing now is, to post the value I always have to reload the browser or use the localhost:3000 in the browser. Is there a way that we can post the value when the node server is started?
Index.js Code
const express = require("express");
const { google } = require("googleapis");
const app = express();
var req = http.request(options, callback);
app.get("/", async (req,res) => {
const auth = new google.auth.GoogleAuth({
keyFile: "credentials.json",
scopes: "https://www.googleapis.com/auth/spreadsheets",
});
const client = await auth.getClient();
// Instance of Google Sheets API
const googleSheets = google.sheets({version: "v4", auth: client});
const spreadsheetId = "1SwZvn0L_wqswv";
// get meta data about spreadsheet
const metaData = await googleSheets.spreadsheets.get({
auth,
spreadsheetId,
});
await googleSheets.spreadsheets.values.append({
auth,
spreadsheetId,
range: "Sheet1!A:B",
valueInputOption: "USER_ENTERED",
resource: {
values: [
["Man", "PostSheet"],
] // end of values array
}
})
});
app.listen(3000, (req,res) => console.log("running on 3000"));
Reference Link
As for reference I used the link from stackoverflow. I was able to post data using the link but unable to post data without using a browser. Basically I just want to post the data when the server is started.