I am confused as how to get the data from the post request and also to then send it to the sheets. I do not know how to also confirm it with the client. any help would be greatly appreciated thank you.
i am trying to build a web app that will be a checkin/checkout system where once someone scans a barcode, the information from that barcode will go directly into the google spreadsheet
var express = require('express');//takes everything from the Express library
var app = express(); //calls the express constructor. app is the server object
var fs = require('fs');
var GoogleSpreadsheet = require('google-spreadsheet');
var creds = require('./client_secret.json');
app.use(express.static('public'));
app.get('/', function (req, res) {
var contents = fs.readFileSync('views/wele.html').toString();
res.send(contents);
});
app.get('/info', function (req, res) {
res.send('Hello Info!');
});
app.get('/checkin', function (req, res) {
var contents = fs.readFileSync('views/no.html').toString();
res.send(contents);
console.log("checking in");
console.log(req);
});
app.get('/checkout', function (req, res) {
var contents = fs.readFileSync('views/no.html').toString();
res.send(contents);
console.log("checking out");
});
app.post('/checkin', function (req, res){ //someone clicks submit on page from
get page
console.log("posting checkin info");
//getthe data from the POST request LOOOK HERE GET INFO FROM POST REQUEST
//send it to Sheets
//body-parser method
var ID = data.ID; // sample
//console.log(id);
// Create a document object using the ID of the spreadsheet - obtained from
its URL.
var doc = new
GoogleSpreadsheet(________);
// Authenticate with the Google Spreadsheets API.
doc.useServiceAccountAuth(creds, function (err) {
/* // Get all of the rows from the spreadsheet.
doc.getRows(2, function (err, rows) {
console.log(rows);
});*/
doc.getInfo(function(err, info) {
console.log('Loaded doc: '+info.title+' by '+info.author.email);
sheet = info.worksheets[0];
console.log('sheet 1: '+sheet.title+' '+sheet.rowCount+'x'+sheet.colCount);
// step();
//look at
});
});
//confirm with the client
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
I am confused as how to get the data from the post request and also to then send it to the sheets. I do not know how to also confirm it with the client. any help would be greatly appreciated thank you.
i am trying to build a web app that will be a checkin/checkout system where once someone scans a barcode, the information from that barcode will go directly into the google spreadsheet
var express = require('express');//takes everything from the Express library
var app = express(); //calls the express constructor. app is the server object
var fs = require('fs');
var GoogleSpreadsheet = require('google-spreadsheet');
var creds = require('./client_secret.json');
app.use(express.static('public'));
app.get('/', function (req, res) {
var contents = fs.readFileSync('views/wele.html').toString();
res.send(contents);
});
app.get('/info', function (req, res) {
res.send('Hello Info!');
});
app.get('/checkin', function (req, res) {
var contents = fs.readFileSync('views/no.html').toString();
res.send(contents);
console.log("checking in");
console.log(req);
});
app.get('/checkout', function (req, res) {
var contents = fs.readFileSync('views/no.html').toString();
res.send(contents);
console.log("checking out");
});
app.post('/checkin', function (req, res){ //someone clicks submit on page from
get page
console.log("posting checkin info");
//getthe data from the POST request LOOOK HERE GET INFO FROM POST REQUEST
//send it to Sheets
//body-parser method
var ID = data.ID; // sample
//console.log(id);
// Create a document object using the ID of the spreadsheet - obtained from
its URL.
var doc = new
GoogleSpreadsheet(________);
// Authenticate with the Google Spreadsheets API.
doc.useServiceAccountAuth(creds, function (err) {
/* // Get all of the rows from the spreadsheet.
doc.getRows(2, function (err, rows) {
console.log(rows);
});*/
doc.getInfo(function(err, info) {
console.log('Loaded doc: '+info.title+' by '+info.author.email);
sheet = info.worksheets[0];
console.log('sheet 1: '+sheet.title+' '+sheet.rowCount+'x'+sheet.colCount);
// step();
//look at https://www.npmjs./package/google-spreadsheet
});
});
//confirm with the client
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
Share
Improve this question
edited Sep 2, 2017 at 18:10
Constantin Guidon
1,89218 silver badges22 bronze badges
asked Sep 2, 2017 at 15:08
KatherineKatherine
31 gold badge1 silver badge2 bronze badges
0
1 Answer
Reset to default 2To get POST
data you need to use body-parser package.
Import it:
var bodyParser = require('body-parser');
And you can use it like this:
app.use(bodyParser.urlencoded({ extended: false }))
Then finally in your middleware, you can access the data like:
var ID = req.body.ID;
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745435719a4627599.html
评论列表(0条)