The simple script to create Database connection using JavaScript.
JavaScript
NodeJS
Steps :
- Open Terminal or Command Prompt.
- Set Path to where File is Located (using cd).
- Type
node databse_connection.js
and Click Enter
var mysql = require("mysql")
var con = mysql.createConnection(
{
host: "localhost",
user: "root",
password: "password", // enter your password here
database: "database_name" // enter database name
})
con.connect(function (err) {
if (err)
throw err;
console.log("Connected");
con.query("create database student", function (err, result) {
if (err)
throw err;
console.log("Database created sucessfully");
})
})