Reputation: 23
when executing the code of the documentation https://developers.google.com/sheets/quickstart/nodejs?fbclid=IwAR0KmCnMNwsPkzuB93pB8YKaWot7IkAtxWqgLANR1Z08kuRKSl-r3DbqMrY#step_3_set_up_the_sample , after putting the key of the URL (google account to authenticate)
this error comes out:
node: 5868) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_CALLBACK]: C
llback must be a function
in maybeCallback (fs.js: 129: 9)
in Object.writeFile (fs.js: 1156: 14)
in storeToken (C: \ Users \ ELIOT \ Desktop \ demoDialoglow \ api.js: 100: 6)
in C: \ Users \ ELIOT \ Desktop \ demoDialoglow \ api.js: 79: 7
in getTokenAsync.then.r (C: \ Users \ ELIOT \ Desktop \ demoDialoglow \ node_modules \ go
gle-auth-library \ build \ src \ auth \ oauth2client.js: 97: 51)
in process._tickCallback (internal / process / next_tick.js: 68: 7)
node: 5868) UnhandledPromiseRejectionWarning: Rejection of uncontrolled promise. This e
Ror originated either by throwing inside an asynchronous function without a capture bl
ck, or rejecting a promise that was not handled with .catch (). (Rejection ID
one)
node: 5868) [DEP0018] DeprecationWarning: unmanaged promise rejects are obsolete
In the future, rejections of promise that are not handled will end the N
Process .js with a non-zero exit code.
Upvotes: 0
Views: 131
Reputation: 1717
This is due to an update to the NodeJS fs module. Simply add an empty function as a third parameter:
fs.writeFile(TOKEN_PATH, JSON.stringify(token), function(){});
or with ES6 syntax:
fs.writeFile(TOKEN_PATH, JSON.stringify(token), () => {});
Refer to this post for more detail: Why node 10 has made it mandatory to pass callback on fs.writeFile()?
Upvotes: 1