Advertisement
Guest User

Untitled

a guest
Oct 6th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. var mysql = require("mysql"),
  2. express = require("express"),
  3. app = express();
  4.  
  5. var connection = mysql.createConnection({
  6. host : "localhost",
  7. user : "root",
  8. password : "",
  9. database : "node"
  10. });
  11.  
  12. connection.connect();
  13.  
  14. app.use(express.bodyParser());
  15.  
  16. app.get("/",function (req,res) {
  17. res.sendfile(__dirname+"/index.html");
  18. })
  19. //connection.end();
  20.  
  21. app.post('/', function(req, res){
  22. console.log(req.body);
  23. connection.query("INSERT into sample SET ?",req.body,function (err,result) {
  24. if (err) throw err;
  25. res.send("Created "+JSON.stringify(result));
  26. });
  27. //res.send("Received"+req.body)
  28. });
  29.  
  30. app.listen(3000);
  31. console.log("listenening on 3000");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement