当我尝试:
$ npm install -g cordova @ latest
总是得到
npm WARN弃用node-uuid@1.4.8:改用uuid模块
mac Os Sierra 10.12
npm v.4.4.4
node v.6.10.2
在安装cordova之前:
$ npm list -g node-uuid
/ usr/local/lib
....(空)
之后:
$ npm list -g node-uuid/usr/local/lib
.... cordova@6.5.0
........ cordova-lib@6.5.0
.......... ..npm @ 2.15.12
................ request@2.74.0
.................... node- uuid@1.4.7
............ request@2.47.0
................ node-uuid@1.4.8
我尝试按照每个建议并安装/卸载一百次.
这是一个npm或cordova问题?
想要实现仅基于firebase的移动网站方法,所以我决定为我的应用程序创建一个简单的API网关,因此我调用云功能端点而不是调用我的外部API并公开我的api密钥.
我按照简单的你好世界的例子,没关系.
一旦我添加了Google样本中声明的请求承诺模块(来自翻译和来自网址缩短示例),我无法继续前进.因为这会产生.
Error parsing triggers: Cannot find module 'request-promise'
Run Code Online (Sandbox Code Playgroud)
使用'request'模块进行测试,结果相同.
我的index.js非常简单
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const request = require('request-promise');
// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions
exports.wxData = functions.https.onRequest((request, response) => {
wwurl = "https://mycurrentendpoint.com/apicall.php?key=1234567890&lat="+request.query.lat+"&lon="+request.query.lon;
response.send(wwurl);
});
Run Code Online (Sandbox Code Playgroud)
现在没有 const request = require('request-promise'); 或const request = require('request'); 它部署好并显示要调用的URL.
真的不知道该怎么做,我已经测试了创建一个新项目并发布了这个
这是我的package.json内容:
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase experimental:functions:shell",
"start": "npm run …Run Code Online (Sandbox Code Playgroud) 我遇到了Lambda 函数的问题,由于某种原因它超时了。
我尝试添加一些 console.log 以了解发生了什么,并且 一切正常,直到外部 http 请求。
我使用npm 模块请求
我可以在请求之前看到日志,但回调中的日志永远不会出现,就像端点没有响应一样。
我错过了什么吗?提前致谢!
var mysql = require('mysql');
var request = require('request');
var config = require('./config.json');
var pool = mysql.createPool({
host: config.dbhost,
user: config.dbuser,
password: config.dbpassword,
database: config.dbname
});
var openWeatherOptions = (device) => {
let domain = 'https://api.openweathermap.org/data/2.5/';
let apiEndpoint = 'weather?';
let params = `lat=${device.lat}&lon=${device.lng}&APPID=${process.env.WEATHER_APP_ID}&units=metric`;
let url = [domain, apiEndpoint, params].join('').toString();
return {
url: url,
method: 'GET',
headers: { 'Content-Type': 'application/json'},
};
}; …Run Code Online (Sandbox Code Playgroud) 在 ES6-ifying 一些 TypeScript 代码(我正在工作的项目在浏览器和 Node 服务器中运行,我想摇动浏览器包),我试图消除使用require并且只使用import. 但是当我这样做时...
import * as request from 'request';
然后调用request(),我在 Node 中得到运行时错误(在使用 babel 使代码 ES5 和 Node 兼容之后):
TypeError: request is not a function
另一方面,如果我这样做:
import request from 'request';
然后 TypeScript 编译器抱怨
error TS1192: Module '"<mypath>/node_modules/@types/request/index"' has no default export.
如果我手动更改已编译的 JS 代码以使用import request from 'request';它,它实际上工作正常......我如何强制 TS 编译器接受此代码并直接通过它?
在NPM-请求库允许我建立HTTP使用一个很好的JSON风格的语法要求,是这样的。
request.post(
{
url: 'https://my.own.service/api/route',
formData: {
firstName: 'John',
lastName: 'Smith'
}
},
(err, response, body) => {
console.log(body)
}
);
Run Code Online (Sandbox Code Playgroud)
但是为了排除故障,我真的需要查看请求的 HTTP 消息正文,因为它会出现在线路上。理想情况下,我正在寻找带有 Node.jsBuffer对象的原始字节表示。似乎很容易得到这个响应,但不是请求。我对multipart/form-data.
我查看了文档和 GitHub 问题,但无法弄清楚。
使用node的http库,这看起来像
var request = http.request(options);
request.setTimeout(milliseconds, callback);
Run Code Online (Sandbox Code Playgroud)
但是,我正在使用包装器库请求,并且没有看到在超时时添加回调的方法.
我正在创建一个API端点来发出http请求并公开该数据,如果请求超时,我希望能够呈现null结果.
对于node.js项目,我想对mapMyIndia API使用反向地理编码,但找不到任何适当的包.
PS:我不想在我的代码中直接使用API,感谢帮助
我遇到了如何将某些 javascript 代码从导入批量转换为 require?中未涵盖的情况。。
\n\n\n\nimport * as assert \xc2\xa0from \'assert\'\nimport * as fs \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0from \'fs\'\nimport * as path \xc2\xa0\xc2\xa0\xc2\xa0from \'path\'\n\nimport hotImport \xc2\xa0from \'hot-import\'\nRun Code Online (Sandbox Code Playgroud)\n\n我将它们转换为,
\n\nconst assert = require(\'assert\')\nconst fs = require(\'fs\')\nconst path = require(\'path\')\n\nconst hotImport = require(\'hot-import\')\nconst hotMod = await hotImport(MODULE_FILE)\nRun Code Online (Sandbox Code Playgroud)\n\n但得到:
\n\nTypeError: hotImport is not a function\nRun Code Online (Sandbox Code Playgroud)\n\n经过一些大量的试验和错误后,我发现这是const { hotImport } = require(\'hot-import\')可行的,但我不知道为什么。
有人可以总结一下什么时候使用const hotImport = require(\'hot-import\')以及什么时候使用const { hotImport …
如何通过使用节点获得利用REST Api所需的PayPal访问令牌?
在我的服务器端,我监听套接字服务器,在我自己的笔记本电脑中,我具有socket.io-client服务,每当我打开它们时,它们都在连接。
当其他人向我的服务器请求时,服务器通过套接字将该请求发送到我的笔记本电脑,然后我的笔记本电脑使用npm-request从本地主机获取数据,并将返回的数据返回给服务器,然后服务器将信息显示给客户端。
这是我服务器端的错误:
/*
throw er; // Unhandled 'error' event
^
**Error [ERR_STREAM_WRITE_AFTER_END]: write after end**
at write_ (_http_outgoing.js:572:17)
at ServerResponse.write (_http_outgoing.js:567:10)
at Socket.<anonymous> (/public_html/api/index.js:37:9)
at Socket.emit (events.js:187:15)
at /public_html/api/node_modules/socket.io/lib/socket.js:528:12
at process._tickCallback (internal/process/next_tick.js:61:11)
Emitted 'error' event at:
at writeAfterEndNT (_http_outgoing.js:634:7)
at process._tickCallback (internal/process/next_tick.js:63:19)
*/
Run Code Online (Sandbox Code Playgroud)
服务器端代码:
/*
throw er; // Unhandled 'error' event
^
**Error [ERR_STREAM_WRITE_AFTER_END]: write after end**
at write_ (_http_outgoing.js:572:17)
at ServerResponse.write (_http_outgoing.js:567:10)
at Socket.<anonymous> (/public_html/api/index.js:37:9)
at Socket.emit (events.js:187:15)
at /public_html/api/node_modules/socket.io/lib/socket.js:528:12
at process._tickCallback (internal/process/next_tick.js:61:11)
Emitted 'error' event at:
at …Run Code Online (Sandbox Code Playgroud) npm-request ×10
node.js ×9
javascript ×4
npm ×3
aws-lambda ×1
cordova ×1
es6-modules ×1
firebase ×1
http ×1
import ×1
module ×1
paypal ×1
request ×1
socket.io ×1
typescript ×1