Although I can successfully query a MS-SQL server, I'm having trouble displaying the result in the browser.
var express = require('express');
const sql = require("mssql/msnodesqlv8");
var app = express();
const main = async() => {
const pool = new sql.ConnectionPool({
server: "example.com",
database: "example",
options: {
trustedConnection: true
}
});
await pool.connect();
const request = new sql.Request(pool);
const query0 = 'select getdate()' // Let's keep it simple..
const result = await request.query(query0);
//console.dir(result);
//console.log(result.recordsets[0])
return result.recordsets[0]
};
app.get('/', function(res, req) {
var a = main()
a.then(function(r) {
console.log(r[0])
res.send(r[0])
}, function(err) {
console.log('fetch error', err)
}).catch(function(error) {
console.log('really bad:', error)
})
})
var server = app.listen(5000, function() {
console.log('Server is running.....');
});
I am able to retrieve the date but encountering the following error:
Server is running..... { '': { 2018-07-17T11:30:02.060Z nanosecondsDelta: 0 } } really bad: TypeError: res.write is not a function at C:\node2mssql2\node2mssql\app0.js:34:13
Any thoughts on what might be causing this? Your help is much appreciated.