node.js 新人,连接mysql 提示缺少 net, fs, tls这三个模块,install 后也不行,
Uncaught (in promise) Error: Cannot find module "fs"
at webpackMissingModule (eval at <anonymous> (index@dev.js:6669), <anonymous>:6:84)
at Object.eval (eval at <anonymous> (index@dev.js:6669), <anonymous>:6:163)
at eval (eval at <anonymous> (index@dev.js:6669), <anonymous>:220:30)
at Object.<anonymous> (index@dev.js:6669)
at __webpack_require__ (manifest@dev.js:586)
at fn (manifest@dev.js:110)
at eval (eval at <anonymous> (index@dev.js:6459), <anonymous>:4:17)
at Object.<anonymous> (index@dev.js:6459)
at __webpack_require__ (manifest@dev.js:586)
at fn (manifest@dev.js:110)
代码:
execuSql() {
console.log('666666666');
var mysql = require('mysql');
var connection = mysql.createConnection({host:'172.22.33.22',user:'root',password:'root',port:'3306',database:'test'});
connection.connect();
var sql = 'SELECT * FROM scipt where id = 1208';
//查
connection.query(sql,function (err, result) {
if(err){
console.log('[SELECT ERROR] - ',err.message);
return;
}
console.log('--------------------------SELECT----------------------------');
console.log(result);
console.log('------------------------------------------------------------\n\n');
});
connection.end();
}
你看你项目的目录有没有node_modules这个文件夹,这里是放你安装的模块的,找不到模块要么就是你没安装,要么就是你没引入。仔细检查一下吧
npm install net, fs, tls
fs 模块是nodejs自带的,重装一下nodejs吧
你写的是服务端代码,请在电脑上安装nodejs 环境,用node xxx.js执行。 chorome览器只用是用了V8引擎来解析js, 像连接数据库,文件读取操作浏览器是不允许的。