I was trying to load the csv file in my nodejs code.
Getting error Error: Neo4jError: CSV file not found: file:…///news.csv
at captureStacktrace (/home/amruthamsuresh/workspace/memgraph/workbench/node_modules/neo4j-driver-core/lib/result.js:611:17)
at new Result (/home/amruthamsuresh/workspace/memgraph/workbench/node_modules/neo4j-driver-core/lib/result.js:105:23)
at Session._run (/home/amruthamsuresh/workspace/memgraph/workbench/node_modules/neo4j-driver-core/lib/session.js:229:16)
at Session.run (/home/amruthamsuresh/workspace/memgraph/workbench/node_modules/neo4j-driver-core/lib/session.js:179:27)
at createNodes (/home/amruthamsuresh/workspace/memgraph/workbench/xmscsv.js:50:21)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
constructor: [Function: Neo4jError] { isRetriable: [Function (anonymous)] },
code: ‘Memgraph.TransientError.MemgraphError.MemgraphError’,
retriable: true
}
I have installed npm I neo4j-driver.
I am using ubuntu.
this is my full code.
const fs = require(‘fs’);
const csv = require(‘csv-parser’);
const neo4j = require(‘neo4j-driver’);
const path = require(“path”);
const { execSync } = require(‘child_process’);
// Function to parse the CSV file and return a Promise
function parseCSVFile(filePath) {
return new Promise((resolve, reject) => {
const results = ;
fs.createReadStream(filePath)
.pipe(csv())
.on(‘data’, (data) => {
results.push(data);
})
.on(‘end’, () => {
resolve(results);
})
.on(‘error’, (error) => {
reject(error);
});
});
}
// Main function to connect to Memgraph and create nodes
async function createNodes() {
const driver = neo4j.driver(‘bolt://localhost:7687’);//, neo4j.auth.basic(‘your-username’, ‘your-password’));
const session = driver.session();
try {
const csvDir = path.join(__dirname, “…/news.csv”);
console.log(Importing data from ${csvDir}
);
const data = await parseCSVFile(csvDir);
// Copy the CSV file to the Memgraph Docker container
execSync(‘sudo docker cp /home/amruthamsuresh/workspace/memgraph/news.csv f60e60b1c260:/news.csv’);
// Process each row from the CSV data
for (const row of data) {
const genre = JSON.parse(row.genre);
const tags = JSON.parse(row.tags);
const name = row.name;
const query = `
LOAD CSV FROM "file:..///news.csv" WITH HEADER IGNORE BAD AS row
CREATE (news:News)
SET news.genre = $genre,
news.tags = $tags,
news.title = $name;
`;
await session.run(query, { genre, tags, name });
console.log(`Created node for ${name}, ${tags}, ${genre}`);
}
} catch (error) {
console.error(‘Error:’, error);
} finally {
session.close();
driver.close();
}
}
// Call the main function
createNodes();
Please i need help with this ASAP.