Agar Franny Agar Franny - 1 year ago 213
Javascript Question

How can I move files to a directory using Node.JS?

When I try

to move files to a directory, I get the following error:

/home/decuge31/node_modules/fs-extra/lib/move/index.js:19 |
var shouldMkdirp = ('mkdirp' in options) ? options.mkdirp : true |
^ |
TypeError: Cannot use 'in' operator to search for 'mkdirp' in undefined |
at [as move] (/home/decuge31/node_modules/fs-extra/lib/move/index.js:19:35) |
at Object.<anonymous> (/home/decuge31/bscBot.js:8:4) |
at Module._compile (module.js:456:26) |
at Object.Module._extensions..js (module.js:474:10) |
at Module.load (module.js:356:32) |
at Function.Module._load (module.js:312:12) |
at Function.Module.runMain (module.js:497:10) |
at startup (node.js:119:16) |
at node.js:902:3

This is my code in file

var fs = require('fs-extra'); // This imports the fs-extra dependency
var request = require('request'); // This imports the request dependency

fs.ensureDir('css'); // This creates a folder called css

request('').pipe(fs.createWriteStream('master.css')); // This downloads the master.css file

fs.move('master.css', 'css'); // This moves master.css to the specified directory, in this case it is called css

Answer Source
var fs = require('fs-extra');
var request = require('request');
fs.move('master.css', 'css/master.css', function (err) {
  if (err)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download