简体   繁体   English

将seriate node.js与Web应用程序连接的最佳方法是什么

[英]What is the best possible approach to connect seriate node.js with a web application

I am actually involved in a POC and looking to build a web app which can display SQL results after hitting a button. 我实际上参与了POC,并希望构建一个Web应用程序,该应用程序可以在按下按钮后显示SQL结果。 Got to know that seriate node.js is a good platform for this. 知道seriate node.js是一个很好的平台。 But unable to find out how to link these components. 但是无法找到如何链接这些组件。 Any help towards this would be appreciable. 任何对此的帮助将是可观的。

You can check the below code 您可以检查以下代码

var webconfig = {
    user: 'login',
    password: 'sa@123',
    server: 'localhost', 
    database: 'TestDB',

    options: {
        encrypt: false // Use this if you're on Windows Azure 
    }
}

var express = require('express');
var sql = require('mssql');
var http = require('http');

var app = express();
var port = process.env.PORT || 8000;

var connection = new sql.Connection(webconfig, function(err) {
    var request = new sql.Request(connection); 
    request.query('select * from Users', function(err, recordset) {
       if(err)      // ... error checks 
            console.log('Database connection error');

    console.dir("User Data: "+recordset);
    });
});


app.listen(port);
console.log(port+' is the magic port');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM