MYsql connection --- newbie here


#1

HI all
I ma just starting with this and what i am trying to do is connect to mysql database after i get a webhook from manychat , at the moment i am getting a error

Error: Cannot find module 'mysql'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/app/app.js:21:15)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)

would love if someone could help me please


MOD EDIT: formatting


#2

Hey @Crashmailman, welcome to the Glitch forum!

That error message probably means that you have a problem with your pnpm module installation; probably the mysql package isn’t installed properly. There can be a number of reasons for this. It will be most helpful to be able to look at your project to offer specific recommendations, but you could start with providing the contents of your package.json file instead.

You could also run enable-pnpm in your project’s console and watch the logs while your project reinstalls its modules. There may be a more useful error message in the installation logs, but those will only show when you run that command, so you’d have to watch carefully.


#3

Thank you so much for the reply i did that and i am still getting

here is my code

package.json
{
  "name": "manychat-devtools-example",
  "version": "0.0.1",
  "description": "An example server for Manychat Devtools.",
  "main": "app.js",
  "scripts": {
    "start": "node app.js"
  },
  "dependencies": {
    "body-parser": "^1.15.0",
    "express": "^4.13.4",
    "request": "^2.72.0"
  },
  "engines": {
    "node": "8.x"
  },
  "author": "Manychat",
  "license": "ISC"
}

app.js

// server.js
// where your node app starts

// init project
var express = require('express');
var app = express();
//const requestPromise = require('request-promise');
 
// we've started you off with Express, 
// but feel free to use whatever libs or frameworks you'd like through `package.json`.

app.use(express.static('public'));


//=======================================================================================
//  Get the Client data from database
//=======================================================================================

//app.get("/Getcompany", function (request, response) {

const mysql = require('mysql');
const connection = mysql.createConnection({
  host: '****',
  user: '***',
  password: '*******',
  database: '***'
});
connection.connect((err) => {
  if (err) throw err;
  console.log('Connected!');
});
//});

MOD EDIT: formatting and remove private data


#4

Ok, you’re not asking Glitch to install the MySQL package which is why Node can’t find it. You want something like this in your package.json:

“request”: “^2.72.0”,
“mysql”: “^2.16.0”

Basically, you need to add that 2nd line. Then your project should install the MySQL package and get you past this error.

Also, I’ve removed your database details from your post, but it’s very possible that they’ve been exposed to anyone who’s viewed the topic. You should at least change your database password as soon as you can.


#5

Thanks very much for that gee i am silly


#6

Not at all! It’s an easy mistake to make and lots of experienced developers have done the same thing at some point!


#7

And that goes for both forgetting a package and exposing a password!


#8

i seem to have got past that part

but for some reason it is crashing here

connection.connect((err) => {
if (err) throw err;
console.log(‘Connected!’);
});
//});

myjs is not good i had someone do this for me and send it (i paid for it) and didnt work so i am trying to get it to work myself sorry for been a pain

at Protocol.handshake (/rbd/pnpm-volume/3160be57-a3d3-4afa-a888-c9055686dbc7/node_modules/.registry.npmjs.org/mysql/2.16.0/node_modules/mysql/lib/protocol/Protocol.js:51:23)

4:14 PM

at Connection.connect (/rbd/pnpm-volume/3160be57-a3d3-4afa-a888-c9055686dbc7/node_modules/.registry.npmjs.org/mysql/2.16.0/node_modules/mysql/lib/Connection.js:118:18)

4:14 PM

Jump to

at Object.<anonymous> (/app/app.js:28:12)

4:14 PM

at Module._compile (module.js:653:30)

4:14 PM

at Object.Module._extensions…js (module.js:664:10)

4:14 PM

at Module.load (module.js:566:32)

4:14 PM


#9

It looks to me (from testing the IP address I removed from your post and the typical MySQL port) that that IP address (defined in the host property) doesn’t have MySQL running on it, or it’s running on a non-standard port. Where did you come by that connection information, and can you confirm you have the right IP Address / host information?


#10

yea its my server :slight_smile: i am in the phpadmin page for it


#11

ok got it working i know it is off topic but when you look at my code and i take the comment from the get.app i get a error any suggestions . i think you know what i am trying to do