I'm trying to connect a MySQL database through Famo.us. But I can't get it done. The folder structure of the app looks like this:
- app (the actually famo.us app)
- content (images etc.)
- lib
- src
- main.js (actually app)
- requireConfig.js
- styles
- grunt
- node_modules
main.js
/*globals define*/
define(function(require, exports, module) {
'use strict';
// import dependencies
var Engine = require('famous/core/Engine');
var ImageSurface = require('famous/surfaces/ImageSurface');
var StateModifier = require('famous/modifiers/StateModifier');
// create the main context
var mainContext = Engine.createContext();
// your app here
var logo = new ImageSurface({
size: [200, 200],
content: '/content/images/famous_logo.png'
});
var logoModifier = new StateModifier({
origin: [0.5, 0.5]
});
mainContext.add(logoModifier).add(logo);
});
Cause it's running on node I tried to install the mysql node_module in the node_modules folder, successfully. But I can't connect to it, because if I try to require mysql with require('mysql') in main.js it thinks I want to try a js file from the src folder. I can't point directly to the node_modules folder, because it gives me a 404 error also and it's not the way to do it according to famo.us' docs.
So i tried to add the mysql code to main.js this way, but it's not working either: mysql node:
require(['mysql'], function(mysql) {
//foo and bar are loaded according to requirejs
//config, but if not found, then node's require
//is used to load the module.
//Now export a value visible to Node.
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'test',
database : 'app'
});
window.console.log(mysql);
});
requireConfig.js
/*globals require*/
require.config({
nodeRequire: require,
shim: {
},
paths: {
famous: '../lib/famous',
requirejs: '../lib/requirejs/require',
almond: '../lib/almond/almond',
'famous-polyfills': '../lib/famous-polyfills/index'
}
});
require(['main']);
I didn't work with requireJS in combination with Node earlier and Famo.us is quite new, so they don't have documentation yet to connect with a mysql database. So I'm quite lost. Is anybody who knows probably a solution for this?