[英]Viewing Node.js code
我是Web開發的新手。 我正在使用Node.js編寫應用程序,並希望使用MySQL。 我不確定網絡技術如何工作,但是訪問我的網站的人能否看到我的數據庫憑據? 根據MySQL文檔( https://github.com/felixge/node-mysql ),這是如何連接到MySQL數據庫。
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret'
});
connection.connect();
connection.query('SELECT 1 + 1 AS solution', function(err, rows, fields) {
if (err) throw err;
console.log('The solution is: ', rows[0].solution);
});
connection.end();
除非您將文件發布為純.js而不是在node.js中執行,否則人們不會看到您的數據庫憑據。
但是,作為一項額外的安全措施,請阻止數據庫與服務器外部的連接,例如設置防火牆以防止端口3306與外部連接,並僅在mysql數據庫中使用“ localhost”用戶。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.