Saturday, 13 April 2019

Help - Sql Server Database Pool

hi there, I am currently in the process of learning how nodejs APIs work and I wanted to attach an mssql server to it.I followed this stackoverflow sample:https://stackoverflow.com/questions/30356148/how-can-i-use-a-single-mssql-connection-pool-across-several-routes-in-an-expressand did the following:users.js:​const express = require("express"); const router = express.Router(); const { sql, poolPromise } = require("./db"); /* GET users listing. */ router.get("/user", function(req, res, next) { res.send("respond with a resource"); }); router.get("/customers", async (req, res) => { try { const pool = await poolPromise; const request = new sql.Request(pool); const result = await request.query("select * from customers"); res.json(result.recordset); } catch (err) { res.status(500); res.send(err.message); } }); module.exports = router; but when i send the request i get the following:Cannot read property 'Request' of undefinedwhat am I doing wrong?any help or guidance towards a solution or another setup is much appreciated!

Submitted April 13, 2019 at 02:43PM by VincentVanclef

No comments:

Post a Comment