mysql - 无法在nodejs中使用npm安装mysql

标签 mysql node.js

我尝试了以下命令,mysql模块没有添加到node_module文件夹中,而且使用mysql的代码抛出错误。

   Your environment has been set up for using Node.js 0.8.3 (ia32) and NPM

C:\Users\Work>npm install mysql
npm http GET https://registry.npmjs.org/mysql
npm http 304 https://registry.npmjs.org/mysql
npm http GET https://registry.npmjs.org/hashish/0.0.4
npm http 304 https://registry.npmjs.org/hashish/0.0.4
npm http GET https://registry.npmjs.org/traverse
npm http 304 https://registry.npmjs.org/traverse
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3855414b495478081601160e" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\mysql
└── <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3bbb2a0bbbaa0bb93e3fde3fde7" rel="noreferrer noopener nofollow">[email protected]</a> (<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="abdfd9caddced9d8ceeb9b859d8598" rel="noreferrer noopener nofollow">[email protected]</a>)

C:\Users\Work>npm install <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="25485c56544965170b150b15084449554d4416" rel="noreferrer noopener nofollow">[email protected]</a>
npm http GET https://registry.npmjs.org/mysql/2.0.0-alpha3
npm http 304 https://registry.npmjs.org/mysql/2.0.0-alpha3
npm http GET https://registry.npmjs.org/require-all/0.0.3
npm http 304 https://registry.npmjs.org/require-all/0.0.3
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="563b2f25273a1664786678667b373a263e3765" rel="noreferrer noopener nofollow">[email protected]</a> node_modules\mysql
└── <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6f1d0a1e1a061d0a420e03032f5f415f415c" rel="noreferrer noopener nofollow">[email protected]</a>

C:\Users\Work>node D:\nodejs\sqlwrite.js

module.js:340
    throw err;
          ^
Error: Cannot find module 'mysql'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (D:\nodejs\sqlwrite.js:1:74)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)

C:\Users\Work>

我已经输入了 github 上显示的命令。

最佳答案

您应该将路径(安装 Node 模块的位置)添加到系统变量中。或者导航到 NodeJS 模块的默认系统路径并安装 NodeJS 模块。这是我的系统的路径:

C:\Users\[用户名]\AppData\Roaming\npm\node_modules

关于mysql - 无法在nodejs中使用npm安装mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11611354/

相关文章:

mysql - 如何在Golang中使用GORM在数据库之间切换?

PHP PDO - 多个 x 字段的单个查询

php - 如何从序列化输出中获取值

node.js - 微软机器人- Node SDK : How to mention a user in Microsoft Teams

javascript - VB.NET TCP 客户端与 NODE-RED TCP 监听器进行双向通信

mysql查询问题

php - 在 PHP 中释放内存

node.js - 使用 npm install 时权限被拒绝

javascript - Node.js/ express 邮寄不工作

javascript - $injector :modulerr AngularJS, 到目前为止尝试了一切