b.writeTextFile how to call from a web inteface

I have a simple need but in node.js I know it can’t be done do to security.
b.writeTextFile does not seem to work either.

My need is for a user to input a file name and have this file name saved on the server for future append to file.
Like saving encoder values.

This will log the user input but “Cannot read property ‘writeFile’ of undefined”

If anyone has any ideas please help.

var fs = require('fs');
var input = document.getElementById('filename');
var fileName = input.value;

function recordToFilename() {
var input = document.getElementById('filename');
var fileName = input.value;
var qw = fileName;

if (qw) {
    alert('value of: ' + qw);
    console.log(qw);
    // demo output
    var myObject = {
        qw: qw,
        fullN: function() {
            return this.qw;
        }
    };

    document.getElementById("demo").innerHTML = myObject.fullN();
    var path = "danny.txt";
    var data1 = "jdsfhadj"
    fs.writeFile(path,data1)
    //end demo output code
    } else {
        alert('Please enter a filename!');
        input.focus();
    }
};

HTML Code:

<html>
<head>
    <title>writeFile</title>
    <script src="jquery.js"></script>
    <script src="bonescript.js"></script>
    <script src="test_3.js"></script>
</head>
<body>

    <label for="filename">Filename</label>
    <input name="filename" id="filename" type="text">

    <a id="enter_button" onclick="recordToFilename();"    href="javascript:void(0);" title="enter">enter name</a>
    <br>
    <p id="demo"></p>
</body>
</html>

Your example was on my todo list, excuse the long post. I found the diagnostic logging helpful in understanding the npm upload package busboy, but you can easily shorten it Using “~/mytmp/” as my temporary directory and tweaking the example at https://www.npmjs.com/package/busboy my server.js file is:

var http = require(‘http’),
path = require(‘path’),
os = require(‘os’),
fs = require(‘fs’);
inspect = require(‘util’).inspect;

var Busboy = require(‘busboy’);

http.createServer(function(req, res) {
if (req.method === ‘POST’) {
var busboy = new Busboy({ headers: req.headers });

busboy.on(‘file’, function(fieldname, file, filename, encoding, mimetype) {
console.log(‘File [’ + fieldname + ']: filename: ’ + filename + ', encoding: ’ + encoding + ', mimetype: ’ + mimetype);
// uncomment next line to use system temporary directory
// var newPath = os.tmpDir();
var newPath = __dirname + “/mytmp”;
var saveTo = path.join(newPath, path.basename(filename));
file.pipe(fs.createWriteStream(saveTo))
file.on(‘data’, function(data) {
console.log(‘File [’ + fieldname + ‘] got ’ + data.length + ’ bytes’);
});
file.on(‘end’, function() {
console.log(‘File [’ + fieldname + ‘] Finished’);
});
});

busboy.on(‘field’, function(fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
console.log(‘Field [’ + fieldname + ']: value: ’ + inspect(val));
});

busboy.on(‘finish’, function() {
console.log(‘Done!’);
res.writeHead(303, { Connection: ‘close’, Location: ‘/’ });
res.end();
});

return req.pipe(busboy);

} else if (req.method === ‘GET’) {

res.writeHead(200, { Connection: ‘close’ });
res.end(’\

\
\
\ \ \ '); } }).listen(8000, function() { console.log('Listening for requests'); });

. . .
------------------------------**-------------------
The contents of this email are confidential to the sender and the ordinary user of the email address to which it was addressed, and may also be privileged. If you are not the addressee of the email, you may not copy, forward, disclose or otherwise use it or any part of it in any form whatsoever. If you have received this email in error, please advise the sender at 214-257-0984. Thank you.
------------------------------**-------------------

May be a bit nick picky, but the above statement bothers me because . . .

a) this is a google group.

b) the code above was written for a software “platform” that is open source, and very likely would have to also be made open source as well - By extension.

c) The hardware discussed in this group is open source, as well as most of the software provided “out of the box”.

That text you referred to in my signature is appropriate for circumstances where [Attorney-Client] or [Attorney-Expert] privileged legal work product is contained in the email. It has no practical bearing on the code’s open source licensing model. I should remember to delete the signature but if I don’t anyone with access to this Google Group is the intended recipient. Sorry for the confusion.

That text you referred to in my signature is appropriate for circumstances where [Attorney-Client] or [Attorney-Expert] privileged legal work product is contained in the email. It has no practical bearing on the code’s open source licensing model. I should remember to delete the signature but if I don’t anyone with access to this Google Group is the intended recipient. Sorry for the confusion.

I understand, and actually thought about not saying anything at all except. . . Recently after talking with someone else in a different format, concerning a different development board. The person I was chatting with had a situation where another person received code, and advice from the person I spoke with, for free. When, in fact the person receiving this code and information should have provided a consultant fee up front . . .

The actual code I felt however could not be “owned” by anyone other than those who owned the hardware IP . . . and who also provides example code / literature on how to use on die hardware modules, etc. And while I feel for the person, who I do actually think deserved a good consultant fee for his services - I could not agree that he could actually own said code . . .

Anyway, I’m no lawyer, and I’m not sure why I felt compelled to comment on your signature, except I just wanted to make it clear to those out there that may not know. Chances are very good that if you’re writing software on Linux. particularly if using a software stack such as Nodejs . . . that you( general term ) possibly do not “own” what you wrote.