2017-04-24 86 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

回答

相关问题