Hi all, I should save query data in a txt file on file system, is it possible to do this using node.js backend?
Apple
November 13, 2023, 2:48pm
2
For NodeJS people:
Create a file or write to a file using custom encoding and custom flags.
I documented how to use the extension in the GitHub repo.
For PHP people:
Hi ,
During project development, I wanted to create a TXT file and add a log to this file. Thanks to Wappler’s expandable feature, it was quite good to prepare it in my own way and use it the way I want. Now I can create a file as I want and add the logs I want to it.
I thought that instead of writing the logs on your site to the database, you might want to write them in a txt file or a file with the extension you want.
Write To File
It is very simple to use, I am sure you will see how simpl…
The data query object must be JSON encoded (there’s a formatter, not sure if it’s in the UI) so it becomes a string, and that can be written to a file
3 Likes
Thanks for the reply, I didn’t quite understand where the module should be installed.
The readme file says to copy it to the /extensions/server_connect/modules
folder but it doesn’t exist in my project.
Apple
November 13, 2023, 3:26pm
4
Indeed, you need to create the folder, it’s not pre-created by default unfortunately
2 Likes
Thanks, everything works fine
Hi Apple, a question, but is it possible to save the file outside the project directory?
For example on a network folder?
I’m trying to give a path different from that of an internal folder but it always generates an error
Apple
November 16, 2023, 4:45pm
7
Looking at the code:
const fs = require('fs/promises');
const util = require('util');
const readFile = util.promisify(fs.readFile);
const path = require('path');
const { toSystemPath } = require("../../../lib/core/path");
exports.WriteFile = async function(options) {
options = this.parse(options);
let path = toSystemPath(options.path);
let content = options.content;
let encode = options.encoding;
let customflag = options.flag;
fs.writeFile(
`${path}`,
`${content}`, { encoding: encode, flag: customflag },
function(err) {
if (err) return console.log(err);
console.log("The file was saved!");
It seems the folder is converted to the project folder (or something like that?), so you’ll probably need to change that line to:
let path = options.path