Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
el script de nodo no se completa

Tengo un script simple para volcar datos en db, que estoy usando junto con el script npm. Estoy tratando de volcar datos en db antes de que se inicie el servidor de aplicaciones de mi nodo. Sin embargo, el script de volcado nunca se completa y, por lo tanto, el script de inicio del servidor no se inicia. Aquí está mi script de volcado:

 const mongodb = require('mongodb') , fs = require('fs') , MongoClient = mongodb.MongoClient , client = new MongoClient(`mongodb://localhost:27017/admin`, { useUnifiedTopology: true }) , docs = fs.readFileSync(`${process.cwd()}/app/scripts/records.json`) client.connect().then(cl => { const dbObj = cl.db('dumpdb') dbObj.collection(`loc_biz_hrs`).insertMany(JSON.parse(docs)).then(result => { console.log(`${result.insertedCount} records inserted`) }) })

y así es como estoy tratando de ejecutarlo usando el script npm:

 "scripts": { "start": "node app/scripts/records.js && nodemon --exec babel-node index.js", "test": "test" }

Simplemente muestra en la terminal 35755 records inserted y se atasca allí y no ejecuta la parte index.js del script.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

intente usar simultáneamente el paquete npm npm i simultáneamente

 "scripts": { "start": "react-scripts start", "dev": ""concurrently \"node app/scripts/records.js\" \"nodemon --exec babel-node index.js\"" }
over 4 years ago · Santiago Trujillo Report

0

No está cerrando la conexión usando cl.close() , así que intente esto:

 const mongodb = require('mongodb') , fs = require('fs') , MongoClient = mongodb.MongoClient , client = new MongoClient(`mongodb://localhost:27017/admin`, { useUnifiedTopology: true }) , docs = fs.readFileSync(`${process.cwd()}/app/scripts/records.json`) client .connect() .then(cl => { const dbObj = cl.db('dumpdb'); dbObj .collection(`loc_biz_hrs`) .insertMany(JSON.parse(docs)) .then(result => { console.log(`${result.insertedCount} records inserted`); cl.close(); }).catch(error => { console.log(error); cl.close(); }) }) .catch(error => { console.log(error); });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!