Slip 30 - B) Create a Node,js file that demonstrate create database and Hospital table (hReg, hName,address, contact) in MySQL.

Solution:

/* Hospital.js*/


var mysql=require('mysql');

var cn=mysql.createConnection({

host:"localhost",

user:"root",

password:"",

database:"mydb"

});

cn.connect(function(err){

      if(err) throw err;

      console.log("connected!");

      var sql="CREATE TABLE Hospital(hReg INT

       AUTO_INCREMENT PRIMARY KEY ,hName

        VARCHAR(20),hAddress VARCHAR(20),contact  INT)";


    cn.query(sql,function(err,result){

       if(err)throw err;

            console.log("Table Created!");

   });

});


C:\Users\NEW\nodex>npm install mysql

C:\Users\NEW\nodex>node Hospital.js

Post a Comment

0 Comments