Skip to content

Instantly share code, notes, and snippets.

@AlexFrazer
Last active March 2, 2016 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexFrazer/951163178e924c2eb7e1 to your computer and use it in GitHub Desktop.
Save AlexFrazer/951163178e924c2eb7e1 to your computer and use it in GitHub Desktop.
Here you can publish from a search page one at a time.
'use strict';
import knex from 'knex';
import express from 'express';
import socket from 'socket.io';
import bodyParser from 'body-parser';
export const app = express();
export const db = knex({ client: 'pg', /** your config here */ });
app.use((req, res, next) => {
req.db = db;
next();
});
export const server = http.createServer(app).listen(8124);
export const io = socket.listen(server);
// some boilerplate code here
// now you can use a route like this
app.route('/products', async function (req, res, next) {
const search = req.db('products').select('*').where(req.queryParams).stream();
search.on('data', d => io.emit('result', d));
search.on('end', res.end.bind(res));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment