2017-04-24 82 views
0

我是nodejs的新手,所以我真的不知道如何完成這項工作。NodeJs:在網頁中運行我的應用程序

我有我的控制檯運行node app.js時創建json輸出的代碼。

現在我想有相同的JSON輸出在我的網站

所以如果有人進入example.com:8000它將運行node app.js

我的代碼是:

'use strict'; 

var pa11y = require(); 

// Create a test instance with some default options 
var test = pa11y({ 

    // Log what's happening to the console 
    log: { 
     debug: console.log.bind(console), 
     error: console.error.bind(console), 
     info: console.log.bind(console) 
    } 

}); 

test.run('example.com', function(error, result) { 
    if (error) { 
     return console.error(error.message); 
    } 

    console.log(JSON.stringify(result)); 
}); 

UPDATE: 我曾嘗試使用expressjs

var express = require('express'); 
var app = express(); 

app.get('/', function(req, res){ 
    res.send("Hello world!"); 
    test.run('example.com', function(error, result) { 
    if (error) { 
     return console.error(error.message); 
    } 

    console.log(JSON.stringify(result)); 
}); 
}); 

「你好字」工作正常。

和所有我試圖從test.run('example.com', function(error, result) {打印輸出沒有任何成功。

什麼,我需要做的,以與expressjs

+0

我寧願你拿[快速教程由教程點](http://www.tutorialspoint.com/expressjs/),然後解決您的問題。 – cdaiga

+0

@cdaiga嗨,這就是我曾嘗試,但沒有奏效。我已經添加了對我的問題的更新。你能看看有什麼不對嗎? – user2413244

回答

相關問題