Thursday 1 June 2017

nodeJS: exposing an API with express and restify

My main server.js looks like:

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

app.use('/api', require('./api/api'));
app.use('/', require('./site'));

app.listen(3000, () => {
  console.log('App listening on port 3000');
});

Idea being the API sits in in the API module, and the site in the site module. So I am trying to structure /api/api.js like so:

const restify = require('restify');
const api = restify.createServer({
    name: 'API'
});

api.get('/people', (req, res, next) => {
    res.send({people: []});
    return next;
});

module.exports = api;

Idea being that /api/people would then return the data. But I am seeing the error Router.use() requires middleware function but got a Object because, well, this is not structured correctly.

How can I get this up and running?



via Wells

No comments:

Post a Comment