Guest User

Untitled

a guest
Nov 7th, 2018
81
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express');
  2. const sql = require('mssql');
  3. const bodyParser = require('body-parser');
  4. const app = express();
  5.  
  6. app.use(bodyParser.json());
  7. app.use(bodyParser.urlencoded({ extended: true }));
  8.  
  9. app.post('/', async ({ body }, res) => {
  10.   try {
  11.     const pool = await sql.connect('mssql://login:senha@servidor/banco');
  12.     const resultado = await pool.request()
  13.       .input('programm', sql.VarChar(50), 'Teste 1 2 3')
  14.       .input('id', sql.VarChar(50), '39')
  15.       .input('title', sql.VarChar(50), 'Finance')
  16.       .query('INSERT INTO dbo.WIDS_API_TEST (programm, id, title) VALUES (@programm, @id, @title');
  17.  
  18.     res.send(resultado);
  19.   } catch(e) {
  20.     console.error(e);
  21.     res.status(500).send('Erro interno');
  22.   }
  23. });
  24.  
  25. const server = app.listen(5000, () => {
  26.   console.log('Server is running..');
  27. });
RAW Paste Data