Created
August 7, 2013 13:14
-
-
Save radiosilence/6173924 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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