Node-Webkit 的 (nwjs) node-remote 用法 [英] Node-Webkit's (nwjs) node-remote Usage
问题描述
如果我想从服务器运行我的应用程序的一些逻辑/功能,我想知道是否有人可以给我一个关于节点远程"如何工作的示例.
I wonder if someone can give me an example about how "node-remote" works if I want to run some of the logic/functions of my application from the server.
比如,在 package.json 中添加 "node-remote" : "hostip" 后我不知道该怎么办,我的服务器应该提供什么?.js 文件具有我想要运行的功能?那么它是这样的: "node-remote" : "myappserver.com/funcs.js" 吗?我对这个很困惑...
Like, I don't know what to do after adding "node-remote" : "hostip" into package.json, what should my server provide? .js file that has the functions I want to run? So is it like: "node-remote" : "myappserver.com/funcs.js" ? I am so confused about this...
我在网上找不到足够的信息,所以一些帮助或至少对baconface"从这个链接回复的更好解释会很有帮助:https://github.com/nwjs/nw.js/issues/3278
I can't find enough information on web about this, so some help or at least a better explanation of "baconface"'s reply from this link would be so helpful: https://github.com/nwjs/nw.js/issues/3278
推荐答案
node-remote
用于公开 node.js + nw.gui API,用于 html 脚本标签和来自您的 javascript 文件网站.就是这样!您可以在这些文件中使用 require
、global
、process
等对象.
node-remote
is used for to expose node.js + nw.gui APIs for html script tags and javascript files coming from your website. That's it! You can use require
, objects like global
, process
in these files.
node-remote
参数本身需要主机的域名或 IP 地址,您希望 nw.js 允许这些主机使用 node.js API,而其他主机无法访问它们.
node-remote
parameter itself expects a domain name or ip address of hosts you want nw.js to allow to use node.js APIs for these hosts while other hosts can't access them.
小例子:
- 配置简单的
package.json
并将node-remote
参数设置为github.com
. - 保存
package.json
. - 打开
nw
应用程序. - 打开页面
https://github.com/
. - 打开
开发者工具
. - 在控制台输入
require('fs').writeFileSync('test.txt', 'Hello, World!');
并回车.
- configure simple
package.json
and setnode-remote
parameter togithub.com
on it. - save
package.json
. - open
nw
application. - open page
https://github.com/
on it. - open
Developer Tools
. - in console type
require('fs').writeFileSync('test.txt', 'Hello, World!');
and hit enter.
现在您应该在 nw 的根目录中看到 test.txt
文件.
Now you should see test.txt
file in nw's root directory.
- 删除
test.txt
. - 编辑您的
package.json
并删除node-remote
字段. - 重复 [2..6] 个动作.
现在您应该在 DevTools 控制台中看到类似 "require" is undefined
的错误
Now you should see error like "require" is undefined
in DevTools console
希望这会有所帮助.
这篇关于Node-Webkit 的 (nwjs) node-remote 用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!