Advertisement
Guest User

app.js

a guest
Aug 22nd, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. /*eslint-env node*/
  2.  
  3. //------------------------------------------------------------------------------
  4. // node.js starter application for Bluemix
  5. //------------------------------------------------------------------------------
  6.  
  7. // This application uses express as its web server
  8. // for more info, see: http://expressjs.com
  9.  
  10. var express = require('express');
  11. var mysql = require('mysql');
  12.  
  13.  
  14.  
  15. // cfenv provides access to your Cloud Foundry environment
  16. // for more info, see: https://www.npmjs.com/package/cfenv
  17. var cfenv = require('cfenv');
  18.  
  19. // create a new express server
  20. var app = express();
  21.  
  22. // serve the files out of ./public as our main files
  23. app.use(express.static(__dirname + '/public'));
  24.  
  25. // get the app environment from Cloud Foundry
  26. var appEnv = cfenv.getAppEnv();
  27.  
  28. // start server on the specified port and binding host
  29. app.listen(appEnv.port, '0.0.0.0', function() {
  30. // print a message when the server starts listening
  31. console.log("server starting on " + appEnv.url);
  32. });
  33.  
  34.  
  35. var con = mysql.createConnection({
  36. host: "us-cdbr-iron-east-04.cleardb.net",
  37. user: "bc0e03c958a64f",
  38. password: "b7c08b6f",
  39. database: "ad_f2305b724dae531"
  40. });
  41.  
  42. /*
  43. var con = mysql.createConnection({
  44. host: "localhost",
  45. user: "root",
  46. password: "root",
  47. database: "node_test"
  48. });
  49. */
  50.  
  51.  
  52. app.get('/submit', function (req, res) {
  53. con.connect(function(err){
  54. if(err){
  55. //console.log('Error connecting to Db');
  56. return;
  57. }
  58. //console.log('Connection established');
  59. });
  60. var queryString = 'insert into node_test (name,city) values ("'+req.query.name+'","'+req.query.city+'")' ;
  61. con.query(queryString, function(err) {
  62. if (err) throw err;
  63. });
  64. res.end("Successful insertion!");
  65. con.end();
  66.  
  67. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement