発生している問題・エラーメッセージ, 前提・実現したいこと
以下のようなコードでfirebaseのrealtime databaseにイベント発生時に
特定のAPIへhttpリクエストを行いたいが"Cannot find module"と出力されてしまう。
"Cannot find module"
該当のソースコード
swift
1exports.helloWorld = functions.database.ref('/match/{id}') 2 .onWrite( (change, context) => { 3 4//ここで"Cannot find module"になり、requestのmoduleが見つからない模様 5var request = require('request'); 6//絶対パスでも確認したが同じエラーが出力される 7var dataString = '{"aps":{"alert":"hello"}}'; 8 9var options = { 10 url: 'https://api.development.push.apple.com/3/device/hogehogehogehogehogeho', 11 method: 'POST', 12 body: dataString 13}; 14 15function callback(error, response, body) { 16 if (!error && response.statusCode == 200) { 17 console.log(body); 18 } 19}
試したこと
以下のコマンドでローカルのターミナル上から直接キーを叩いたら機能することを確認済み。
curl -v -d '{"aps":{"alert":"hello"}}' --http2 --cert Certificates.pem:1234 https://api.development.push.apple.com/3/device/hogehogehogehogehogeho
以下の記事を参考にpath指定先の確認変更
※変更後にはターミナルを再起動を実施
・https://qiita.com/nbkn/items/01a11392921119fa0153
>npm root -g /usr/local/lib/node_modules >node -e "console.log(global.module.paths)" [ '/vagrant_data/p062/node_modules', '/vagrant_data/node_modules', '/node_modules' ] >export NODE_PATH=/usr/local/lib/node_modules
やりたいこと
以下のようなcurlコマンドをNode.jsに変換して使用したい。
curl -v -d '{"aps":{"alert":"hello"}}' --http2 --cert Certificates.pem:1234 https://api.development.push.apple.com/3/device/6a25342c9d1941c73b37c5c28f6788efe0f7a8e681ce440f15a8eb61e679cb63
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。