0

I'm making a react native app and I want to get some data on MySQL database. I made a javascript file doing that but I don't know how to link this class with my react component.

I tried to include it as a module in my component:

var api = require('../../api/APIConnection');

... but I'm having an error:

"Unable to resolve module crypto from 'User/Documents/X/node_modules/mysql/lib/Connection.js

and I can't figure it out.

Here is my javascript module:

module.exports = {

getMySQL()
{
    if (this.mysql == null)
        return require('mysql');
    else
        return this.mysql;
},

connect()
{
    // Connect to database
    con = mysql.createConnection({
        host: "localhost",
        user: "root",
        password: "",
        port: 8889,
        database: "..."
    });

    etc...
},

Thank you for help!

Koko
  • 89
  • 9
  • Crypto module can't be called like in NodeJS. You can have more information here https://stackoverflow.com/questions/29836434/requiring-unknown-module-crypto-in-react-native-environment. Otherwise you can try to install this library https://github.com/mvayngrib/react-native-crypto – Gabriel Diez Aug 11 '17 at 23:17
  • Thanks for your help, I'm gonna try – Koko Aug 11 '17 at 23:28

0 Answers0