Sunday, 1 December 2019

How to use NodeJS http server with PostgreSQL?

Hello,I'm using digitalocean with a managed PostgreSQL database.What happens is that there is no response sent or error is shown, it just shows a timeout.const http = require("http"), port = 8080; const {Client} = require("pg") const reqHandler = (req, res) => { const url = req.url.slice(4) const client = new Client(/*my db login*/) client .query("SELECT * FROM hardware") .then(data => res.end(JSON.stringify(data))) .catch(err => console.log(e.stack)) //res.end(JSON.stringify(url)) } const server = http.createServer(reqHandler) server.listen(port, err => { if(err) return console.log(err) })

Submitted December 01, 2019 at 09:00PM by distro607

No comments:

Post a Comment