Rohit Dhiman Rohit Dhiman - 3 months ago 35
Javascript Question

How to integrate Angular theme in Node + mysql+ express

I am new to node, angular and express.. Please help me if u can.

I have created REST API using node+express+mysql already,
Now I have to integrate this blur-admin theme into existing project ..
After following instructions i am able to run theme with gulp separately but not know how to connect it with mysql or existing project.

I use

nodemon SERVER
to run existing project

SERVER.js

var express = require("express");
var mysql = require("mysql");
var bodyParser = require("body-parser");
var md5 = require('md5');
var rest = require("./REST.js");
var app = express();

var helmet = require('helmet');
app.use(helmet());

app.disable('x-powered-by');

function REST(){
var self = this;
self.connectMysql();
};

REST.prototype.connectMysql = function() {
var self = this;
var pool = mysql.createPool({
connectionLimit : 100,
host : 'localhost',
user : 'root',
password : 'phpmyadmin',
database : 'myApp',
debug : false
});
pool.getConnection(function(err,connection){
if(err) {
self.stop(err);
} else {
self.configureExpress(connection);
}
});
}

REST.prototype.configureExpress = function(connection) {
var self = this;
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
var router = express.Router();
app.use('/api', router);
var rest_router = new rest(router,connection,md5);
self.startServer();
}

REST.prototype.startServer = function() {
app.listen(3000,function(){
console.log("All right ! I am alive at Port 3000.");
});
}

REST.prototype.stop = function(err) {
console.log("ISSUE WITH MYSQL n" + err);
process.exit(1);
}

new REST();


Use
gulp serve
to run blur-admin theme

gulpfile.js

'use strict';

var gulp = require('gulp');
var wrench = require('wrench');

/**
* This will load all js or coffee files in the gulp directory
* in order to load all gulp tasks
*/
wrench.readdirSyncRecursive('./gulp').filter(function(file) {
return (/\.(js|coffee)$/i).test(file);
}).map(function(file) {
require('./gulp/' + file);
});


/**
* Default task clean temporaries directories and launch the
* main optimization build task
*/
gulp.task('default', ['clean'], function () {
gulp.start('build');
});


NOW i don't know how to merge them both

Answer

While searching on Internet I found the hint on youtube MEAN stack tutorial video. After that I followed these steps:

Moved angular js "blur-admin" theme to public folder of express executed command

 gulp serve

to run client side and on express folder executed command

nodemon SERVER

To run server side on deferent port. Than made REST API on express as required. Used this API on client side theme controller as

$http.get('http://192.168.1.96:4000/api/apiname').
      success(function(data) {
       //code here
      });