1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
var http = require('http'); var moment = require('moment'); process.env.TZ = "Asia/Shanghai"; http.createServer(function (request, response) { var sql = require('mssql'); sql.close(); //连接方式1:"mssql://用户名:密码@ip地址(无需端口号)/SqlServer名/数据库名称" //连接方式2:"mssql://用户名:密码@ip地址:1433(默认端口号)/数据库名称" sql.connect("mssql://sa:s1a2@127.0.0.1/DBNAME").then(function () { new sql.Request().query('select top 10 * from TABLENAME').then(function (result) { response.writeHead(200, { "content-type": "text/html;charset=utf-8;" }); result.recordset.forEach(row => { response.write(row.ID + ' - ' + row.Name + ' - ' + moment(row.DateTime).utc().format("YYYY-MM-DD HH:mm:ss") + "<br>"); }); response.end(); }).catch(function (err) { console.log(err); }); }).catch(function (err) { console.log(err); }); }).listen(8886); |
引用:
https://blog.csdn.net/u010668495/article/details/50817136