0

I am new at nodejs so i dont really know how to make this work.

I have code which creates json output when i run node app.js from my console.

now i want to have the same json output in my website

so if someone enter example.com:8000 it will run the node app.js

My code is:

'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: i have tried to use 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));
});
});

"Hello word" is working fine.

and all what i have tried to print the output from the test.run('example.com', function(error, result) { without any success.

what i need to do to make this work with expressjs

user2413244
  • 231
  • 4
  • 16
  • I will prefer you take [Express tutorials by Tutorials point](http://www.tutorialspoint.com/expressjs/), then resolve your issue. – cdaiga Apr 24 '17 at 08:17
  • @cdaiga HI, that's what i have tried but did not work. i have added an update to my question. can you look what's wrong? – user2413244 Apr 24 '17 at 09:09

1 Answers1

-1

I advise you to study (express)[http://expressjs.com/] or (koa)[http://koajs.com/] frame commbine with (nodejs API)[https://nodejs.org/dist/latest-v6.x/docs/api/],it's easy to study,helpful to understand.

Kermit
  • 1,062
  • 6
  • 10