FAQ Database Discussion Community


error write large file got request entity too large

javascript,node.js,post,stream,fs
I use the following code to send from the browser body(via postman ) file content which is large file. before for small file I use the following which work perfect fs.writeFile(filePath, req.body, 'utf8', function (err) { ... now I use the following app.post('/bb',function(req,res){ var filePath = 'C://test.txt'; var writeStream =...

In a node script how can I monitor a file for changes and get the updated content?

javascript,node.js,fs
I'm writing a script to monitor a file. Whenever the file changes it needs to print to the appended content to the console. I'm dabbling with fs.createReadStream but it doesn't seem to send anymore data over the stream when the file is appended to. I'm also just plain new to...

Removing the last character from file stream in node.js (fs module)

javascript,json,node.js,string,fs
Using node.js, I am trying to build an array of objects and write them to a file. To do this, I'm using the built in fs library. After calling var file = fs.createWriteStream('arrayOfObjects.json'); and file.write('[') I run several asynchronous functions to eventually append objects like this: file.write(JSON.stringify(objectToAppend) + ',\n') I...

NodeJS, changing file location

node.js,fs
I'm trying to move a specific file into a folder (which I create in case it doesn't exist) but for some reason I get the error all the time, events.js:72 // <- this isn't even an existing file in my project :o throw er; // Unhandled 'error' event ^ Error:...

Node fs.watch to read changes only

node.js,logging,fs
fs.watch('log-file', function(event, filename) {}); only returns the file name that was changed. Is it possible to only get what was actually changed? I don't want to read the entire file, and rather want to know what was modified from my file (in my case, there is always addition to a...

fs.writeFile callback never gets called, same for WritableStream.write, etc

node.js,callback,fs
I am writing a small text file (~500B) but, strangely, I get an empty file if I write using asynchronous methods such as fs.writeFile(..) (or WriteableStream's write/end method). This works: var scanInfo = getScanInfo( core ); // returns several lines delimited by \r\n fs.writeFileSync( filename, scanInfo, 'ascii' ); This creates...

Why is this fs.readFile loop not pushing its results to my array? [duplicate]

javascript,node.js,fs
This question already has an answer here: Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference 3 answers #!/usr/bin/env node var fs = require('fs') , async = require('async') , program = require('commander') program .version('0.0.1') .usage('<keywords>') .parse(process.argv) async.waterfall([ fs.readdir.bind(fs, __dirname), parseHTML, ],...

NodeJS: zlib.gunzip() on file contents returns Error: incorrect header check

javascript,node.js,gzip,zlib,fs
My script takes file data, interprets it, and spits it out in a different format. The user can input a URL or upload a file, and the file refence for either of these can be XML or GZIP (which I then decompress). What works: Parsing XML + GZIP from URL...

Node CSV Parser that streams asynchronously, reads line by line and has the ability to pause and resume stream [closed]

javascript,node.js,parsing,csv,fs
I am attempting to find a CSV Parser library or a combination of a stream transformation library and CSV Parser that would allow me to take lines upon request (pausing and resuming). Ive found some examples of line by line read streams however those generally deal with plain text instead...

how to list all tags xml in node.js

javascript,xml,node.js,xml-parsing,fs
Here is my XML: <?xml version="1.0" encoding="utf-8"?> <!-- 1 = video , 2 = html , 3 = pdf --> <stage_type>2</stage_type> <resource_name>http://www.XXX</resource_name> I want to get <resource_name>. I'm using xml2js. When I use: var parser = new xml2js.Parser(); fs.readFile('./' + file, function(err, data) { parser.parseString(data, function (err, result) { console.dir(result);...

How do I chain multiple promises?

javascript,node.js,promise,bluebird,fs
I'm not quite sure, and maybe I'm missing something obvious, but I cannot figure out how to chain two promises. My callback-based code looks something like this: async.series([ function (cb) { // Create the directory if the nodir switch isn't on if (!nodir) { fs.mkdir('somedirectory', function (err) { if (err)...

ReactJS errors with rendering basic html component via variable

reactjs,require,fs
I am trying to pass a string for the jsx template name to a component that will be responsible for just rendering basic html only components with no interaction (we have a lot). 'use strict'; import React from 'react'; export default class TemplateLoader extends React.Component { displayName = 'TemplateLoader' constructor(props)...

How to simulate error returned from fs.readFile for testing purposes?

node.js,unit-testing,mocha,fs,chai
I am new to test-driven development and am trying to develop an automated testing suite for my application. I have successfully written tests that verify the data received from a successful call to Node's fs.readFile method, but as you will see in the screenshot below, when I test my coverage...

Reading files in multiple directories, matching filenames with their data using Node and Promises

javascript,node.js,promise,fs
I have an array of directories. var directories = ['/dir1', '/dir2']; I want to read all files under these directories, and in the end have an object that matches filenames with their base64/utf8 data. In my case these files are images. The resulting object might look like: var result =...

Using node readdir and getting an undefined error not sure why learnyounode

javascript,node.js,fs
When I run the below list[i] on line 14 returns as undefined and I am not sure why. Especially since my log on line 10 returns as expected. below is the code, 1 var fs = require('fs'); 2 var thatDir = process.argv[2]; 3 var ext = process.argv[3]; 4 var newfile;...

Cannot read file with nodejs

javascript,node.js,fs
I use the following code to read a file from my desktop. When I run the server and use some request I don't see anything in the debugger. What am I missing here? fs = require('fs'); fs.readFile('‪C:\Users\i123\Desktop\test.txt', 'utf8', function (err,data) { if (err) { return console.log(err); } console.log(data); res.send(data); });...

Node.js FS write a somewhat large image file?

javascript,node.js,fs
So to solve the canvas toDataUrl security issue, I am going to request an image on the server and write it to my server to serve the client my hosted version of the image. I am requesting images that have the proper rights. var imageId = shortid.generate(); fs.writeFile('./externalImages/'+imageId+'.jpg', 'http://upload.wikimedia.org/wikipedia/commons/5/58/LeBron_James_3409937543.jpg', function...

nodeJS, moving a file to a new folder

node.js,fs
I'm trying to move an existing file into a new folder (which isn't exist) I tried it like var source = fs.createReadStream(file.thumbnail.path); var dest = fs.createWriteStream('./public/uploads/'+ user._id + '/' + file.myfail.name); source.pipe(dest); but I keep getting this error Error: ENOENT, open './public/uploads/553283d3216c3895055612dd/18f1b232024ac9d7a5d398dc9291e160.jpg' I tried also using __dirname but it doesn't...

stats.isFile() doesn't recognize file from a path

javascript,node.js,fs
I am trying to recognize a path being a path of a file using fs.stat and fs.lstat fs.stat('/img/items/item.jpg', function (err, stats) { var isDir = stats.isDirectory(); var isFile = stats.isFile(); console.log('isDir: ', isDir); console.log('isFile: ', isFile); }); However the message says that it is a dir and isFile is false....

How to create a file using user input in nodejs?

node.js,jade,fs
I have a text area, where the user type in their text. Once they click save the content in the text area is send to the server side. In the server side I want to use the content to create a file. I have a variable called "usercode" which holds...

Exit Node Process After Successful fs.appendFile

node.js,fs
I'm having trouble create processes in parallel with Node while exiting when they're done with a simple HTTP GET request. I've noticed that if I fire a process.exit() inside of a callback for appendFile, some files will not be created or appended in a Node cluster setup. Ideally, the way...

`fs.mkdir` is creating the directory with different permissions than those specified

node.js,unix,permissions,fs
Due to the modules my node program uses, it requires root to run. This is because it has to run a HTTP server on port 80 (and as you know, lower ports like that require root in order to be used). But, this program also uses a fs method to...

Node js plugin permissions

node.js,plugins,permissions,sails.js,fs
I create a web server with Sails.js, and want to allow third dev to create node.js plugins installable from a web page (store). My problem is I don't want this plugin to require sails (or other critical modules) and have access to database and services and do what they want....