Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*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);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement