Why is my code not getting executed

insertData.js:-

const mysql= require(‘mysql2’)

const insert = {
name: process.argv[2],
age: parseInt(process.argv[3]),
city: process.argv[4]

}

const connection = mysql.createConnection({
host: ‘localhost’ ,
database: ‘mytestdb’,
user: ‘myuser’,
password: ‘mypass’
})

connection.query(
INSERT INTO persons (name, age, city) VALUES ( '${insert.name}' , '${insert.age}' , '${insert.city}' ),

function(err, results){

    if (err){
        console.error(err)
    }

    else{
        console.log(results)
        console.log("Inserted successfully")

    }
    
    connection.close();
}

)

Output:-
Deeptis-MacBook-Air:Express with SQL deeptisharma$ node .\mysql_scripts\insertData.js xyz 11 Delhi

internal/modules/cjs/loader.js:969
throw err;
^

Error: Cannot find module ‘/Users/deeptisharma/Desktop/Express with SQL/.mysql_scriptsinsertData.js’
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
at Function.Module._load (internal/modules/cjs/loader.js:842:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: ‘MODULE_NOT_FOUND’,
requireStack: []
}

@sharma.deepti182 node can’t find your file insertData.js, check if you have correctly taken the path, and defined the file in the required directory

I’ve changed the file name to insert_data.js
here’s the screenshot of my code, terminal and debug console

@sharma.deepti182 as you can see, in the first image your path is incorrect (to be exact the “/” was not correct), in the second one path is correct, but arguments are not passed. Pass the cmd arguments along with node command and it will run.

both the images are the output of the single command one is of the terminal while the other is of the debug console can you tell what should exactly be written in the terminal because I’ve tried it multiple times but it gives the same error and please check the code whether it needs any correction

@sharma.deepti182 try this in your command terminal

node mysql_scripts/insert_data.js Anny 35 Delhi

problem is with your usage of “/” use need to use the forward slash in unix paths, not the backward one