![](/img/trans.png)
[英]How do you include a resource or template file with an npm package and then load them in node?
[英]How do you include a custom npm package to Google Dialogflow?
我一直在尝试将包“alphanum-increment”添加到我对 Google Dialogflow 的实现中。 我找到了几个将它包含在依赖项下的 package.json 中的指针,但找不到包含它的确切方法。
提前感谢您的解决方案
答案非常简单,因为您说要将其包含在 package.json 中。 您必须包含 npm 包的名称。
{
"some": "crazyPropsFoo",
"engines": {},
"scripts": {},
"dependencies": {
"actions-on-google": "^1.5.x",
"firebase-admin": "~4.1.2",
"firebase-functions": "~0.5",
"alphanum-increment": "0.0.2", // Here you include yours
}
}
然后你只需要在你的“index.js”文件中引入这个包:
var PackageObj = require("alphanum-increment").PackageObject;
var yourVar = new PackageObj();
因此,我只需指出我将从包中使用的功能即可完成此操作。
const {increment} = require("alphanum-increment");
并且在任何您喜欢使用该功能的地方,都可以直接包含它
var orgStr = "N0001";
var updStr = increment(orgStr);//updStr = N0002
同样可以通过以下方式实现 -
const alphanumOp = require(alphanum-increment);
//In your function
var updStr = alphanumOp.increment(orgStr);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.