[英]Node can't find module that's in local dir
I have downloaded a twilio node module into a local directory where my project is. 我已经将twilio节点模块下载到了项目所在的本地目录中。 But when I run the node file, it throws an error. 但是,当我运行节点文件时,它将引发错误。 Below the error here, I've outlined the directory. 在此错误之下,我概述了目录。
The error: 错误:
gamacbook:twilioapp gattra$ node app.js
module.js:340
throw err;
^
Error: Cannot find module 'node_modules/twilio/lib'
My local directory is: 我的本地目录是:
twilioApp
|_app.js
|_index.html
|_main.css
|_script.js
|_node_modules
|_twilio
|_lib
There are obviously a bunch of files in twilio
directory but i'm trying to access those in lib
. 显然在twilio
目录中有一堆文件,但我正在尝试访问lib
。
My code is: 我的代码是:
var accountSid = "removed";
var authToken = "removed";
var client = require('node_modules/twilio/lib')(accountSid, authToken);
app.get('/', function () {
client.messages.create({
body: "Today is awesome and you rock!",
to: phoneNumber,
from: "removed"
}, function (err, message) {
process.stdout.write(message.sid);
})
})
That's not how you should use modules in node. 那不是应该在节点中使用模块的方式。 Simply: 只是:
var twilio = require('twilio')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.