wrong routing with koa-router in koa

  frameworks, javascript, koa, node.js, routes

I am learning Koa, with basic exercise, but i can´t achieve implement a simple routing, with the code that i got from this page, and this is what i did:

var koa = require('koa');
var router = require('koa-router'); //require it
var app = new koa();
var ro = router();
//and we'll set up 2 routes, for our index and about me pages
ro.get('/hello', getMessage);

function *getMessage() {
    this.body = "Hello world!";
 };
app.use(ro.routes());
app.listen(8008);
console.log('Koa listening on port 8008');

i did´t get any specific error, because the app run with the command code index.js, but i can see any print in the page that i routed.

and i only have 1 file in my folder myproyectoks, and it is index.js, and that’s the file that i’m working.

any information that you need pls ask me :D, because i could be forgot something.

Source: Ask Javascript Questions

LEAVE A COMMENT