Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const {Pool} = require('pg');
- //const connectionString = process.env.DATABASE_URL || 'postgres://localhost:5432/springmvctutorial';
- var http = require("http");
- var express = require('express');
- const router = express.Router();
- const app = express();
- var bodyParser = require('body-parser');
- var apiVersion = '/api/v1/';
- const poo = new Pool({
- database: 'springmvctutorial',
- host: 'localhost',
- user: 'postgres',
- password : 'root',
- port: 5432,
- max: 20,
- idleTimeoutMillis: 30000,
- connectionTimeoutMillis: 2000,
- })
- app.use( bodyParser.json() ); // to support JSON-encoded bodies
- app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
- extended: true
- }));
- //create app server
- var server = app.listen(3030, "localhost", function () {
- var host = server.address().address
- var port = server.address().port
- console.log("Example app listening at http://%s:%s", host, port)
- });
- router.post('/api/v1/postData', (req, res, next) => {
- poo.connect((err, client, release) => {
- if (err) {
- return console.error('Error acquiring client', err.stack);
- }
- client.query('INSERT INTO items(text, complete) values(1,false)', (err, result) => {
- release();
- if (err) {
- return console.error('Error executing query', err.stack);
- }
- console.log(result.rows);
- });
- });
- });
- module.exports = router;
- http://127.0.0.1:3030/api/v1/postData
- {
- "text":"user@gmail.com",
- "complete": true
- }
Add Comment
Please, Sign In to add comment