Node-Webkit 的 (nwjs) node-remote 用法 [英] Node-Webkit's (nwjs) node-remote Usage

查看:94
本文介绍了Node-Webkit 的 (nwjs) node-remote 用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想从服务器运行我的应用程序的一些逻辑/功能,我想知道是否有人可以给我一个关于节点远程"如何工作的示例.

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 文件网站.就是这样!您可以在这些文件中使用 requireglobalprocess 等对象.

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.

小例子:

  1. 配置简单的package.json并将node-remote参数设置为github.com.
  2. 保存package.json.
  3. 打开nw 应用程序.
  4. 打开页面https://github.com/.
  5. 打开开发者工具.
  6. 在控制台输入 require('fs').writeFileSync('test.txt', 'Hello, World!'); 并回车.
  1. configure simple package.json and set node-remote parameter to github.com on it.
  2. save package.json.
  3. open nw application.
  4. open page https://github.com/ on it.
  5. open Developer Tools.
  6. 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.

  1. 删除test.txt.
  2. 编辑您的 package.json 并删除 node-remote 字段.
  3. 重复 [2..6] 个动作.

现在您应该在 DevTools 控制台中看到类似 "require" is undefined 的错误

Now you should see error like "require" is undefined in DevTools console

希望这会有所帮助.

这篇关于Node-Webkit 的 (nwjs) node-remote 用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆