Kashyap Nadendla
Kashyap Nadendla

Reputation: 21

Converting a string object to a file in node js

I'm creating an application that outputs employee data based on user search, I want to upload this to my slackbot and I'm trying to use files.upload. I'm a beginner in node so I don't know how to convert my output to a file so I can upload it to Slack.

Upvotes: 1

Views: 754

Answers (1)

Suman Kumar Dash
Suman Kumar Dash

Reputation: 704

It is so simple. Let's see an example. Lets you get data from a database

const fs = require('fs');
let directory = '/temp/data';
let dbdata= 'Hello' // this data you got from database

fs.writeFile(directory, dbdata, function(err) {
if(err) {
    return console.log(err);
}
console.log("File has been saved");
}); 

// if you want synchronous then you can use this
fs.writeFileSync(directory, dbdata);

Upvotes: 1

Related Questions