daily pastebin goal
35%
SHARE
TWEET

Untitled

a guest Oct 17th, 2017 364 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const {Pool} = require('pg');
  2.  
  3.  
  4.  
  5. //const connectionString = process.env.DATABASE_URL || 'postgres://localhost:5432/springmvctutorial';
  6.  
  7. var http = require("http");
  8. var express = require('express');
  9. const router = express.Router();
  10. const app = express();
  11. var bodyParser = require('body-parser');
  12.  
  13. var apiVersion = '/api/v1/';
  14.  
  15.  
  16. const poo = new Pool({
  17.   database: 'springmvctutorial',
  18.   host: 'localhost',
  19.   user: 'postgres',
  20.   password : 'root',
  21.   port: 5432,
  22.   max: 20,
  23.   idleTimeoutMillis: 30000,
  24.   connectionTimeoutMillis: 2000,
  25. })
  26.  
  27.  
  28.  
  29. app.use( bodyParser.json() );       // to support JSON-encoded bodies
  30. app.use(bodyParser.urlencoded({     // to support URL-encoded bodies
  31.   extended: true
  32. }));
  33.  
  34. //create app server
  35. var server = app.listen(3030,  "localhost", function () {
  36.   var host = server.address().address
  37.   var port = server.address().port
  38.   console.log("Example app listening at http://%s:%s", host, port)
  39. });
  40.  
  41.  
  42. router.post('/api/v1/postData', (req, res, next) => {
  43.  
  44.   poo.connect((err, client, release) => {
  45.     if (err) {
  46.       return console.error('Error acquiring client', err.stack);
  47.     }
  48.     client.query('INSERT INTO items(text, complete) values(1,false)', (err, result) => {
  49.       release();
  50.       if (err) {
  51.         return console.error('Error executing query', err.stack);
  52.       }
  53.       console.log(result.rows);
  54.     });
  55.   });
  56.  
  57. });
  58.  
  59. module.exports = router;
  60.    
  61. http://127.0.0.1:3030/api/v1/postData
  62.    
  63. {
  64. "text":"user@gmail.com",
  65. "complete": true
  66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top