Node-Webkit's (nwjs) node-remote Usage

前端 未结 2 630
既然无缘
既然无缘 2021-01-22 02:45

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.

Like, I don\'t

相关标签:
2条回答
  • 2021-01-22 03:25

    Sicne this has been posted "node-remote" has change slightly. Here is an example:

    "node-remote": "*://*",
    

    Direct Links:

    • Notes about changes from v0.12 to v0.13 - http://docs.nwjs.io/en/latest/For%20Users/Migration/From%200.12%20to%200.13/
    • Formatting of "node-remote": http://docs.nwjs.io/en/latest/References/Manifest%20Format/#node-remote
    0 讨论(0)
  • 2021-01-22 03:36

    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 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.

    Little example:

    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.

    Now you should see test.txt file in nw's root directory.

    1. delete test.txt.
    2. edit your package.json and remove node-remote field.
    3. repeat [2..6] actions.

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

    Hope this helps.

    0 讨论(0)
提交回复
热议问题