Skip to content

Instantly share code, notes, and snippets.

@radiosilence
Created August 7, 2013 13:14
Show Gist options
  • Save radiosilence/6173924 to your computer and use it in GitHub Desktop.
Save radiosilence/6173924 to your computer and use it in GitHub Desktop.
http = require 'http'
util = require 'util'
net = require 'net'
pg = require 'pg'
conString = "postgres://qrs:qrs@localhost/qrs"
httpServer = http.Server (req, res) ->
pg.connect conString, (err, client, done) ->
if err
return util.error "Could not connect to PostgreSQL #{err}"
res.writeHead 200,
'content-type': 'application/json'
client.query 'SELECT * FROM instruments_instrument LIMIT 5', (err, result) ->
if err
util.error err
return res.end("Error in query #{err}")
done()
try
res.write JSON.stringify result.rows
catch err
util.error err
res.end '\n'
httpServer.listen 1337
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment