Created
October 4, 2017 06:41
-
-
Save devesh2605/4905f448e1bec88b9c8b370f8d0209f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Strored Procedure*/ | |
/* | |
CREATE PROCEDURE 'GetAllData' () | |
BEGIN | |
SELECT * FROM Employee; | |
END$$ | |
*/ | |
/* | |
* Nodejs Code | |
*/ | |
var express = require('express'), | |
mysql = require('mysql'), | |
bodyParser = require('body-parser'), | |
app = express(); | |
app.use(bodyParser.json()); | |
var port = 3000; | |
var database = mysql.createPool({ | |
connectionLimit : 100, | |
host: 'localhost', | |
user: '***', | |
password: '***', | |
database: 'dbName', | |
port: 3306 | |
}); | |
app.get('/data',function(req,res){ | |
var appData = {}; | |
let sql = 'CALL GetAllData()'; | |
database.getConnection(function(err,connection){ | |
if(err){ | |
appData['error'] = 1; | |
appData['data'] = 'Internal server error'; | |
res.status(500).json(appData); | |
}else{ | |
connection.query(sql,function(err,rows,fields){ | |
if(err){ | |
appData['error'] = 1; | |
appData['data'] = 'Error running stored procedure'; | |
res.status(500).json(appData); | |
} | |
appData['error'] = 1; | |
appData['data'] = rows; | |
res.status(200).json(appData); | |
}); | |
connection.release(); | |
} | |
}); | |
}); | |
app.listen(port,function(){ | |
console.log('Server running on port',port); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment