如何在google计算引擎上将node.js连接到mysql?

如何在google计算引擎上将node.js连接到mysql?,mysql,node.js,google-compute-engine,Mysql,Node.js,Google Compute Engine,我正在谷歌计算引擎上运行一个实例。我在这个实例上安装了mysql和node.js 我已将以下内容放入index.js文件中: const mysql = require("mysql"); var mysql_connection = mysql.createConnection( { host: "instance external IP", user: "my_user_name", password: "my_pw", database: "my_db"

我正在谷歌计算引擎上运行一个实例。我在这个实例上安装了mysql和node.js

我已将以下内容放入index.js文件中:

const mysql = require("mysql");

var mysql_connection = mysql.createConnection(
{
    host: "instance external IP",
    user: "my_user_name",
    password: "my_pw",
    database: "my_db"
}
);

mysql_connection.connect(err => 
    {
        if(err) throw err;
        console.log("Connected to the database.");
    });
我得到这个错误:

Error: Cannot find module 'mysql'
如何在计算引擎上将node.js连接到mysql?
我是否需要获得不同的主机地址而不是外部IP,如果需要,它是什么或在哪里找到它?
需要(“mysql”)是问题吗?如果是,我如何解决这个问题以在计算引擎实例上找到mysql模块?

根据上面的评论对话,使用以下方法安装mysql节点模块:

npm install mysql

您安装了MySQL模块(例如“NPM安装MySQL”)吗?您也可以考虑连接到本地主机或UNIX套接字,而不是外部IP,但这不是您的直接问题。我还制作了一个数据库和表。你能看到根目录中的node_modules文件夹吗?还有很多文件夹,因为mysql npm有依赖关系?@robsiemb你是对的,我一定使用了apt,但忘记了,因为在Asif提到检查node_模块后,我看了,没有看到任何mysql文件夹,所以我运行了npm安装mysql,它们现在都在那里,node.js脚本现在没有抛出错误。好吧,谢谢你们两位的帮助,省去了我很多麻烦,我想知道我做错了什么。