Express, Bookshelf.js & Postgres. ES6 style using Babel.
- Grunt
- Babel Compiler
- Express
- Bookshelf.js
- SASS
- BrowserSync
# clone a copy
git clone https://github.com/kurtisdunn/Express-Bookshelf-Postgres-ES6.git
cd ES6-ExpressJS-Starter
# get it going:
npm install
# run it
node dist/server.js
# Compile ES6 to ES5
grunt compile
# run up a development version:
grunt dev
This build uses Bookshelf.js to persist our data from postgresql, easily mapping table relations in a minimal promise based format.
# Model
const Make = Bookshelf.Model.extend({
tableName: 'make',
models: () => {
return this.hasMany(Model);
}
});
# Query
Make.where('id', req.params.id).fetch().then((make) => {
res.json(make);
}).catch((err) => {
console.error(err);
});
###Endpoints
GET /api
- Returns nothingGET /api/make/:id
- Fetch make by idGET /api/make/:id/models
- Fetch models by makeGET /api/models/:id
- Query model by model name