I was trying to insert a record in the table of employees, then I got this error in node.js(vs code).
So, I googled it and he said, “Prompt and window are not defined in the node environment.”
What does that mean? Can’t I use a prompt in node.js?
This is my code:
const mysql = require("mysql");
const con = mysql.createConnection({
host: "localhost",
user: "root",
password: "root",
database: "crud"
});
con.connect((error)=>{
if(error)
throw(error);
console.log("Connected to dataBase");
let id = prompt("Enter id: ");
let name = prompt('Enter employee name: ');
let sal = prompt('Enter sal: ');
var sql = "INSERT INTO employee (e_id, e_name, e_sal) VALUES ("+Number(id)+ ", '"+name+"','" +Number(sal)+ "')";
con.query(sql, (err, result)=>{
if(err) throw err;
console.log("1 record successfully inserted in the table.");
});
});