Skip to content

Instantly share code, notes, and snippets.

@hashrock hashrock/server.js
Created Dec 27, 2017

What would you like to do?
Koa my boilerplate
const path = require('path');
const koaBody = require('koa-body');
const Koa = require('koa');
const app = module.exports = new Koa();
const datastore = require('nedb-promise')
const _ = require('koa-route');
const serve = require('koa-static');
var gsjson = require('google-spreadsheet-to-json');
let DB = datastore({
filename: 'db.json',
autoload: true
app.use(_.get('/items', async function(ctx) {
ctx.body = await DB.find({})
app.use(_.get('/menus', async function(ctx){
var result = await gsjson({
spreadsheetId: 'SPREADSHEET_ID',
// other options...
ctx.body = result;
ctx.body = e;
app.use('/items', async function(ctx) {
var item = ctx.request.body
await DB.insert(item)
ctx.body = {item: item}
if (!module.parent) app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.