【发布时间】:2016-05-04 12:25:31
【问题描述】:
我已按照http://expressjs.com/en/starter/installing.html 此处的步骤安装 express NodeJS 应用程序。安装后我们移动到“myapp”目录,然后我们从https://github.com/aws/aws-iot-device-sdk-js安装了“aws-iot-device-sdk”。
在 node_modules 目录中创建了 aws-iot-device-sdk 目录。
在公共目录中,我们通过创建“index.html”的示例开始探索。在浏览器中启动 NodeJS 服务器后,我们尝试打开 http://localhost:3000,这里 index.html 屏幕被打开了。
index.html - 我们需要“aws-iot-device-sdk”来运行 AWS - IOT 应用程序的脚本标签,但这里出现以下错误。
Uncaught ReferenceError: require is not defined
下面是index.html文件的代码
<!DOCTYPE html>
<html>
<script>
function clicked(){
var awsIot = require('aws-iot-device-sdk');
}
</script>
<body>
<input type="submit" onclick="clicked()" value="Click here to send email">
</body>
</html>
为了重定向到 index.html,我们在 app.js 中使用了以下代码
app.use(express.static('public'));
请帮助我解决这个问题。
谢谢, 拉克什·卡尔瓦。
【问题讨论】:
-
您能否使用堆栈跟踪以及导致该错误的代码位更新您的问题?应该有行文件和行号。
标签: javascript node.js amazon-web-services express require