Node.js Alexa Task Issue
我目前正在编写一个 node .通过AWS Lambda编写js Alexa任务,我一直在try 编写一个函数,该函数从OpenWeather API接收信息,并将其解析为一个名为weather
的变量.相关代码如下:
var request = require('request');
var weather = "";
function isBadWeather(location) {
var endpoint = "http://api.openweathermap.org/data/2.5/weather?q=" + location + "&APPID=205283d9c9211b776d3580d5de5d6338";
var body = "";
request(endpoint, function (error, response, body) {
if (!error && response.statusCode == 200) {
body = JSON.parse(body);
weather = body.weather[0].id;
}
});
}
function testWeather()
{
setTimeout(function() {
if (weather >= 200 && weather < 800)
weather = true;
else
weather = false;
console.log(weather);
generateResponse(buildSpeechletResponse(weather, true), {});
}, 500);
}
我在Cloud9和其他IDE中无数次运行了这个片段,它似乎工作得非常完美.但是,当我将其压缩到一个包中并将其上载到AWS Lambda时,会出现以下错误:
{
"errorMessage": "Cannot find module '/var/task/index'",
"errorType": "Error",
"stackTrace": [
"Function.Module._load (module.js:276:25)",
"Module.require (module.js:353:17)",
"require (internal/module.js:12:17)"
]
}
我安装了模块js、请求和许多其他 node 模块,这些模块应该可以让代码运行,但似乎没有任何东西可以解决这个问题.这是我的目录,以防万一:
- planyr.zip
- index.js
- node_modules
- package.json
有人知道问题是什么吗?