能不能把"tedious"模块browserify一下,这样nodejs程序就可以在浏览器里运行了?
Is it possible to browserify the "tedious" module so that the nodejs program can be run in the browser?
我是 Node.js 的初学者,我目前正在构建一个 Node.js 程序,该程序使用 "tedious" 模块访问和查询 Microsoft Azure SQL 数据库(见下面的代码)并将数据放到 html 网页上。我想在浏览器中 运行 这段代码,所以我使用 browserify 将模块捆绑在一起。但是,当这段代码为运行 in Google Chrome时,返回如下错误:require is not defined。有解决办法吗?甚至可以使用 Chrome 中的繁琐模块吗?如果不可能,我是否需要在 Node.js 应用程序和网页之间使用中间服务器?
var Connection = require('tedious').Connection;
var config = {
userName: 'hackmatch',
password: 'hackvalley123!',
server: 'hackmatch.database.windows.net',
options: {encrypt: true, database: 'AdventureWorks'}
};
var connection = new Connection(config);
connection.on('connect', function(err) {
// If no error, then good to proceed.
console.log("Connected");
});
var Request = require('tedious').Request;
var TYPES = require('tedious').TYPES;
在此先感谢您的帮助! :)
没有。该模块只能在Node中使用。
繁琐依赖于node.js net
模块来连接数据库服务器。此模块在浏览器上没有等效项,因为网页无法建立任意网络连接。
即使可以在浏览器中使用此模块,这也是一个糟糕的主意。您将允许您网站上的任何人直接连接到您的 SQL 服务器和 运行 SQL 查询。 This can only end badly.
我是 Node.js 的初学者,我目前正在构建一个 Node.js 程序,该程序使用 "tedious" 模块访问和查询 Microsoft Azure SQL 数据库(见下面的代码)并将数据放到 html 网页上。我想在浏览器中 运行 这段代码,所以我使用 browserify 将模块捆绑在一起。但是,当这段代码为运行 in Google Chrome时,返回如下错误:require is not defined。有解决办法吗?甚至可以使用 Chrome 中的繁琐模块吗?如果不可能,我是否需要在 Node.js 应用程序和网页之间使用中间服务器?
var Connection = require('tedious').Connection;
var config = {
userName: 'hackmatch',
password: 'hackvalley123!',
server: 'hackmatch.database.windows.net',
options: {encrypt: true, database: 'AdventureWorks'}
};
var connection = new Connection(config);
connection.on('connect', function(err) {
// If no error, then good to proceed.
console.log("Connected");
});
var Request = require('tedious').Request;
var TYPES = require('tedious').TYPES;
在此先感谢您的帮助! :)
没有。该模块只能在Node中使用。
繁琐依赖于node.js net
模块来连接数据库服务器。此模块在浏览器上没有等效项,因为网页无法建立任意网络连接。
即使可以在浏览器中使用此模块,这也是一个糟糕的主意。您将允许您网站上的任何人直接连接到您的 SQL 服务器和 运行 SQL 查询。 This can only end badly.