Advertisement
Guest User

Untitled

a guest
Sep 6th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var mysql=require('mysql');
  2. var express=require('express');
  3. var bodyParser=require('bodyParser');
  4.  
  5. var app= express();
  6. app.use (bodyParser.json());
  7. app.use (bodyParser.urlencoded({ extended: true }) );
  8.  
  9. var server=app.listen(process.env.PORT||8000, function(err){
  10.     if(err)throw err;
  11.     console.log('Connected to port 8000');
  12. });
  13.  
  14. var conn=mysql.createConnection({
  15.     host: 'localhost',
  16.     user: 'root',
  17.     password: 'rootpass',
  18.     database: 'mydb'
  19.    });
  20. conn.connect(function(err){
  21.      if(err)throw err;
  22.      console.log('Connected');
  23.     });
  24. /*
  25. conn.query ('CREATE DATABASE mydb', function(err, res){
  26.        if(err)throw err;
  27.        console.log(res);
  28.     });
  29. conn.query('CREATE TABLE IF NOT EXISTS laptop\
  30.            (  ID                INT NOT NULL,\
  31.               procesor          VARCHAR(30) NOT NULL,\
  32.               placa video       VARCHAR(30) NOT NULL,\
  33.               RAM               INT,\
  34.               spatiu stocare    INT,\
  35.               rezolutie         VARCHAR(30) NOT NULL)',
  36.               function(err, res){
  37.               if(err) throw err;
  38.               console.log(res);
  39.               }
  40.     );
  41. */
  42. app.get('/insert.html',function(req,res){
  43.     res.sendFile(__dirname + '/insert.html');
  44. });
  45. app.post('/insert',function(req,res){
  46.     var arr= [[req.body.id, req.body.procesor, req.body.placavideo,
  47.                req.body.ram, req.body.spatiustocare, req.body.rezolutie]];
  48. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement