I am new to Node.js. I want to create mysql connection and insert data into the database and access it later. I installed, node.js, then using npm installed 'mysql' and 'faker'. Using node.js I successfully connected to mysql, created database and tables(code in mysql1.js in the folder NODE-JS).
Then I went ahead to create fake data (code in fake_data.js) to insert into the table. screenshot of vscode
var faker = require("faker");
let first_name = faker.name.firstName(); let last_name = faker.name.lastName();
console.log(Employee: ${prefix} ${first_name} ${last_name} ${suffix}
);
But this time I got error
code: 'MODULE_NOT_FOUND',
path: 'D:\\DATABASES\\NODE-JS\\node_modules\\faker\\package.json',
requestPath: 'faker'
package.json file contains the following dependencies
{
"dependencies": {
"faker": "^6.6.6",
"mysql": "^2.18.1"
},
"name": "node-js",
"version": "1.0.0",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}
I tried,
var faker = require("./faker");
even then it throws error
please help me to rectify the problem. thanks
The owner of faker deleted it from GitHub at v6.6.6
You can see that here:
https://github.com/marak/Faker.js/
So it is up to the community to complete it
The new repository:
https://github.com/faker-js/faker
This is the official, stable fork of Faker.
Please replace your faker
dependency with @faker-js/faker
.
npm install @faker-js/faker --save-dev
const { faker } = require('@faker-js/faker');