node.js googleapis library cannot find module '/node_modules/googleapis/apis/youtube/v3' - node.js

I'm using the the official Google Apis node.js library to fetch YouTube user info. I already have this working fine in another project, but for some reason I'm getting a strange error in this one. The goal is to fetch a list of videos scoped to a particular playlist id.
I'm using Mithril.js with coffeescript. Here's the relevant snippet:
google = require 'googleapis'
Properties.controller = (options = {}) ->
#showVideos = (playlistId) =>
youtube = google.youtube('v3')
youtube.playlistItems.list({part:'snippet', playlistId: playlistId}).then(videos) ->
console.log videos
The google client loads fine, but on this line:
youtube = google.youtube('v3')
I get the following error:
Uncaught Error: Unable to load endpoint youtube("v3"): Cannot find module '/node_modules/googleapis/apis/youtube/v3'
I use this exact same code in another project on the same computer in a neighboring directory. They are both using the same version of googleapis (I copied the working folder to this project just to be doubly sure).
I tried doing this with some of the other client endpoints such as with the usage examples. None of them work. So it must be some kind of path variable?

Related

Importing BetaAnalyticsDataClient from #google-analytics/data returns Webpack 5 errors

I am trying to create a custom dashboard on the angular app I am building. I want to use the data from Google Analytics 4 using Google Analytics Data API. I've successfully ran the scripts provided in their tutorial Using Node.JS client libraries (https://developers.google.com/analytics/devguides/reporting/data/v1/quickstart-client-libraries?hl=en_US).
I've ran the quickstart script they have provided using Node.JS and was able to get the expected response. However, when I try to ran the same script on my angular app via importing the script to fetch returned values, "ng serve" returns webpack 5 errors.
The issue was importing the BetaAnalyticsDataClient. Whenever I import it, the nodemon returns webpack errors.
The structure is like this:
simple component structure
I have a 'site-statistics.component' with its html and scss files.
I have a script named 'google-analytics.ts' inside the subfolder "services".
site-statistics.component imports an exported function from google-analytics.ts
If the issue is my usage of the Google Analytics Data API client library, I want to know how I would be able get the response from the script and send it to my angular component.
Options I've tried, but failed:
Tried adding a resolve.fallback on webpack.config.ts. However, issue still persists.
Tried setting paths to each packages on my TSCONFIG.JSON.
Tried using react-scripts-rewired
If the issue is the way I use the Google Analytics Data API client library, I want to know how I would be able get the response from the script and send it to my angular component.

Firebase docs reference unknown module

Firebase has this piece of information here at https://firebase.google.com/docs/functions/locations:
Client-side location selection for callable functions Regarding the callable function, client callable setups should follow the same guidelines as HTTP functions. The client can also specify a region, and must do so if the function runs in any region other than us-central1.
To set regions on the client, specify the desired region at
initialization:
var functions = firebase.app().functions('us-central1');
I've been trying to find which node module firebase is referring to but I have had no luck.
I know that it is not 'firebase-admin' or 'firebase-functions' but thats about it.
Anyone have any ideas what this might be referring to?
Edit:
I have now also tried using this with the imports require('firebase') and require('firebase/app') (as suggested) but neither of those seem to work. I also tried generating the app with const app = firebase.initializeApp({}); and then running app.functions("region") or app().functions("region") but i keep receiving TypeErrors saying functions is not a function and app is not a function respectively.
firebase.app().functions('us-central1'); is a part of the firebase-js-sdk. With source code documented on GitHub
NPM component is #firebase/functions, that is documented on the npmjs.com.
However, it is not intended for standalone usage, and should be used along with package Firebase.
You can install it using:
$ npm i firebase

gas-local Reference Err SpreadsheetApp is not defined

I'm trying to set up my app script project using clasp and test it locally using gas-local, I have reached the step of testing but I got this error ReferenceError: SpreadsheetApp is not defined.
gas.js
//require gas-local itself
var gas = require('gas-local');
//require your downloaded google apps script library from src subfolder
var glib = gas.require('./src');
where src is my google app script project folder, however when I node gas I got the ReferenceError: SpreadsheetApp is not defined
The idea from using gas-local is that I want to know my GAS cloudProject ID programatically, so I thought I would trigger any method locally and get the project-id from the error message that will be thrown.
I would appreciate anyone writes a step by step guide with screenshots if possible showing how to accomplish this process.

How do I get my deployed React.js app to use API secret keys? I'm using Heroku confing vars but still not working

Problem:
I created a simple React app (using Javascript and Node) that uses the GitHub API to search for users and return information about them. I need to use a GitHub oauth key so that I can make authenticated API requests. However, I am having trouble giving my deployed app (using Heroku) the key without hard-coding it into the API call. I'm fairly new at this so any help would be great! I linked the github repo at the bottom of this post.
I have tried several things which I will explain below:
Attempt 1:
I created a file where I set my GitHub key to a variable and exported it (Image of code)
I put said file in the .gitignore
I imported the variable in the files where I made API calls and used them it directly in the API call. (Image of API call)
This worked on my dev environment but (obviously) did not work on my deployed Heroku app because it had no idea what the variable was. (Image of error)
Attempt 2:
I configured variables in Heroku and set GITHUB_KEY to my key. (Image of Heroku variable setting).
Next, I checked that Heroku recognized this variable by running the command heroku config:get GITHUB_KEY and received the correct key in response (Image of terminal)
In my secrets file, I set the variable like so: process.env.GITHUB_KEY = 'a93b2c21918b42df5a28e0e529c627ee22c60de4'; (Image of setting variable using process.env)
And then I use it in my API calls on the frontend: const res = await fetch(
'https://api.github.com/users/${this.state.input}?access_token=${process.env.GITHUB_KEY}'
);.
However, I get the following error: SearchBar.js:32 GET https://api.github.com/users/livmarx?access_token=undefined 401 (Unauthorized). (Image of error).
So, I know that I'm misunderstanding how process.env works but cannot seem to figure it out! Any clarification would be super helpful.
Here is the link to my github repo: https://github.com/livmarx/zilliow-challenge

Node Module not being referenced on server

I am trying to link the Mandrill library into my node project.
I have backtracked it right upto the following code which "stops" the project. This code is from the mandril API documentation.
var mandrill = require('mandrill-api/mandrill');
var mandrill_client = new mandrill.Mandrill('My KEY');
I have installed the mandril api using npm install mandrill-api and I can see it my node_modules folder. However when I deploy the project to the server the application stops running. It clearly is not referencing properly but I don't see how.
The code is being called in config.js. I'm sure I'm making a stupid mistake.

Resources