Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
hellnodejs/hello.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
28 lines (21 sloc)
696 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//import koa | |
var koa=require('koa'); | |
//import koa-router which is used to router user request to its path | |
var Router=require('koa-router'); | |
//import koa-bodyparser which is used to extract parameters from requests | |
//create a koa instance and store it in app variable | |
var app=new koa(); | |
var router=new Router(); | |
router.get('/api/v1.0',welcomeapi); | |
//use the root routes | |
app.use(router.routes()); | |
//run server on port 3000 | |
app.listen(3000); | |
//import the router we defined in articles.js | |
var articles = require('./routes/articles.js'); | |
//apply thhe routes as a middleware | |
app.use(articles.routes()); | |
function welcomeapi(cnx,next) | |
{ | |
cnx.body={message:'Welcome to Oktob API version 1.0'}; | |
} |