簡體   English   中英

在AppJ和Node.js中使用外部模塊

[英]Using external modules within AppJs and nodejs

我已經使用AppJS / NodeJS和edge構建了一個基本的演示應用程序。

這是app.js配置文件的相關部分-基本上,它僅引用外部模塊。

.......
window.on('ready', function(){
  console.log("Window Ready");
  window.process = process;
  window.module = module;
  window.dns = require('native-dns');
  window.edge = require('edge');
  window.fs = require('fs');
  window.frame.openDevTools();
  ..........

以下是index.html主頁中相關的javascript部分:

.......
   function myFunction1()
    {
        var question = dns.Question({
           name: 'www.google.com',
            type: 'A'
        });

    var req = dns.Request({
        question: question,
        server: { address: '8.8.8.8', port: 53, type: 'udp' },
        timeout: 1000
    });

    req.on('timeout', function () {
        console.log('Timeout in making request');
    });

    req.on('message', function (err, answer) {
        answer.answer.forEach(function (a) {
            console.log(a.address);
        });
    });

    req.on('end', function () {
        console.log('Finished processing request');
    });

    req.send();

}

 function myFunction2()
    {
  var helloWorld = edge.func('async (input) => { return ".NET Welcomes " + input.ToString(); }');

    helloWorld('JavaScript', function (error, result) {
        if (error) throw error;
        console.log(result);
    });
}

..........

如果我調用使用另一個nodejs模塊(DNS查找)的myFunction1(),則它可以正常工作。 但是,如果我調用使用edge的myFunction2(),則會出現以下錯誤!

Uncaught TypeError: Property 'func' of object [object Object] is not a function  

我已經花了幾個小時了,因為無法弄清為什么會這樣!

您是否嘗試過在app.js中(即在nodejs中)運行相同的myFunction2代碼? 可能func函數在邊緣對象上不存在。 檢查文檔,也許您需要執行諸如window.edge = require('edge')。Edge;之類的操作。

或類似的東西來掌握您目前認為的物體。 您還可以執行console.log(window.edge)並查看其輸出(在節點和運行開發工具(F12)的瀏覽器中)。

/西蒙

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM