SHARE
TWEET

Untitled

a guest Jul 19th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var express = require('express');
  2. var sql = require('mssql');
  3.  
  4. var config = {
  5.     user: 'username',
  6.     password: 'password',
  7.     server: 'localhost',
  8.     database: 'mydatabase'
  9. };
  10.  
  11. var query_result;
  12.  
  13. sql.connect(config).then(pool => {
  14.     return pool.request()
  15.     .query('select * from test')
  16. }).then(result => {
  17.     console.dir(result); //here it logs the results
  18.     query_result = result.recordset;
  19. });
  20.  
  21. console.dir(query_result) // here it logs "undefined"
  22.  
  23. /* GET home page. */
  24. router.get('/', function(req, res, next) {
  25.     res.render('index',
  26.         {
  27.             result: query_result
  28.         }
  29.     );
  30. });
  31.  
  32. module.exports = router;
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