We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c38d311 commit b9f2419Copy full SHA for b9f2419
src/file.js
@@ -0,0 +1,22 @@
1
+const path = require('path')
2
+const fs = require('fs')
3
+const csv = require('fast-csv')
4
+
5
+// Archivo a enviar
6
+const creaArchivo = async (c,data) => {
7
+ const dirFile = path.resolve(__dirname,'../public'),
8
+ nameFile = 'usuarios_' + new Date().toLocaleDateString() + '.csv'
9
+ pathFile = dirFile + '/' + nameFile
10
+ let file
11
+ c('Creando archivo...')
12
+ fs.createWriteStream(pathFile).close()
13
+ c('Archivo creado: ' + nameFile)
14
+ c('Escribiendo datos...')
15
+ file = await csv.writeToPath(pathFile, data, { headers: true })
16
+ file.close()
17
+ c('Archivo guardado exitosamente')
18
+ c('Ubicación: ' + pathFile)
19
+ return { pathFile, nameFile }
20
+}
21
22
+module.exports = creaArchivo
0 commit comments