How to use node-fs - 10 common examples

To help you get started, we’ve selected a few node-fs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stimulant / ampm / server.js View on Github external
currentScheme += '.';
        }
    }

    // Set the current working directory to the location of the config file,
    // so that paths in the config file are relative to itself.
    process.chdir(path.dirname(configPath));

    $$serverState.saveState('lastConfig', $$config);
}

console.log('Server starting up.');

// Load the shared state plugin file.
global.$$plugin = null;
if ($$config.plugin && fs.existsSync($$config.plugin)) {
    var plugin = require(path.resolve($$config.plugin)).Plugin;
    global.$$plugin = new plugin();
}

// A container for all the network transports, generally accessed via $$network.transports.
global.$$network = new Network({
    config: $$config.network
});

// The manager of the application process, controlling restarts and heartbeats.
global.$$persistence = new Persistence({
    config: $$config.persistence
});

// The logging manager.
global.$$logging = new Logging({
github koopjs / koop-core / lib / ExportWorker.js View on Github external
cache.db.select(task.dbKey, opts, function (err, entry) {
    if (err) {
      koop.log.error('Error selecting rows from the DB', task.dbKey, opts, err)
      throw err
    }
    if (fs.existsSync(filePart)) fs.unlinkSync(filePart)

    fs.writeFile(filePart, JSON.stringify(entry[0]), function () {
      // TODO why build this here?
      // we could open a file handle and push each layer into the file via io
      var vrtPartial = ''
      vrtPartial += filePart
      vrtPartial += ''

      fs.appendFileSync(task.files.rootVrtFile, vrtPartial)
      // tick up the number of complete pages
      self.completed++
      job.progress(null, null, pageLen)
      cb()
    })
  })
}, 4)
github bipio-server / bipio / tools / setup.js View on Github external
// ----------

sparseConfig.timezone = process.env.SYSTEM_TZ;

// some systems report EDT while not having EDT zoneinfo
if ('EDT' === sparseConfig.timezone) {
  sparseConfig.timezone = 'EST';
}

// Session Secret
crypto.randomBytes(48, function(ex, buf) {
  sparseConfig.server.sessionSecret = buf.toString('hex');
});

var logPath = path.resolve(__dirname + '/../') + '/logs';
if (!fs.existsSync(logPath)) {
  fs.mkdirSync(logPath, 0755);
}


// JWT Signing Key
if (!sparseConfig.jwtKey) {
  crypto.randomBytes(48, function(ex, buf) {
    sparseConfig.jwtKey = buf.toString('hex');
  });
}

// override data dir
if (process.env.NODE_DATA_DIR) {
  sparseConfig.modules.cdn.config.data_dir = path.resolve(process.env.NODE_DATA_DIR);
}
github stimulant / ampm / model / logging.js View on Github external
BaseModel.prototype.initialize.apply(this);
        global.logger = new winston.Logger({
            exitOnError: $$persistence.get('exitOnError')
        });

        // Set up console logger.
        if (this.get('console').enabled) {
            this.get('console').handleExceptions = !$$persistence.get('exitOnError');
            logger.add(winston.transports.Console, this.get('console'));
        }

        // Set up file logger.
        if (this.get('file').enabled) {
            // Create the log file folder.
            var dir = path.dirname(this.get('file').filename);
            if (!fs.existsSync(dir)) {
                fs.mkdirSync(dir);
            }

            this.get('file').timestamp = function() {
                return moment().format('YYYY-MM-DD HH:mm:ss');
            };

            this.get('file').handleExceptions = !$$persistence.get('exitOnError');
            logger.add(require('winston-daily-rotate-file'), this.get('file'));
        }

        // Set up email.
        if (this.get('mail').enabled) {
            var subject = this.get('mail').subject;
            if (subject) {
                subject = subject.replace('{hostname}', os.hostname());
github TylerBarnes / wordsby / src / createTemplatesJson.js View on Github external
return new Promise((resolve, reject) => {
    const trimmedPaths = existingTemplateFiles.map(fullPath =>
      fullPath.replace(templatesPath + "/", "").replace(/\.js|\.jsx/gi, "")
    );

    const templateJsonString = JSON.stringify(trimmedPaths);
    const filepath = path.resolve(`./wordsby/data/templates.json`);
    const dir = path.resolve("./wordsby/data");

    if (!fs.existsSync(dir)) {
      fs.mkdirSync(dir, { recursive: true });
    }

    // Save templates array to the public folder. to be consumed by WP for template switching and preview urls
    fs.writeFile(filepath, new Buffer.from(templateJsonString, "utf8"), err => {
      if (err) reject(err);
      resolve();
    });
  });
};
github koopjs / koop-core / lib / ExportWorker.js View on Github external
cache.getCount(job.data.table, job.data.options, function (err, count) {
      if (err) {
        koop.log.error('Error getting count from the DB', err)
        throw err
      }
      // if we can handle the data in one page
      if (count <= job.data.options.limit) {
        singlePage(job, done)
      // if we already have a VRT on disk
      } else if (fs.existsSync(job.data.paths.rootVrtFile) && !job.data.options.ignore_cache) {
        createFromVRT(job, done)
      // we need to start from scratch
      } else {
        multiPage(job, count, done)
      }
    })
  })
github mattburns / exiftool.js / test / testWithNode.js View on Github external
fs.readFile('report/template.html', 'utf8', function(err, data) {
            if (err) {
                return console.log(err);
            }
            var result = data.replace(/htmlbody/g, html).replace(/cssparent/g, "../../../../report");

            var reportFile = 'generated/reports/' + image + '.html';
            var parentDir = reportFile.substring(0, reportFile.lastIndexOf("/"));
            if (!fs.existsSync(parentDir)) {
                fs.mkdirSync(parentDir, 0777, true);
            }
            fs.writeFile(reportFile, result, 'utf8', function(err) {
                if (err) {
                    return console.log(err);
                } else {
                    callback(coverageSummary);
                }
            });
        });
    };
github mattburns / exiftool.js / testWithNode.js View on Github external
fs.readFile('report/template.html', 'utf8', function(err, data) {
            if (err) {
                return console.log(err);
            }
            var result = data.replace(/htmlbody/g, html);

            var reportFile = 'generated/reports/' + image + '.html';
            var parentDir = reportFile.substring(0, reportFile.lastIndexOf("/"));
            if (!fs.existsSync(parentDir)) {
                fs.mkdirSync(parentDir, 0777, true);
                fs.linkSync('report/css', parentDir + '/css');
                fs.linkSync('report/fonts', parentDir + '/fonts');
                fs.linkSync('report/js', parentDir + '/js');
            }
            fs.writeFile(reportFile, result, 'utf8', function(err) {
                if (err) {
                    return console.log(err);
                } else {
                    callback(coverageSummary);
                }
            });
        });
    };
github bipio-server / bipio / tools / setup.js View on Github external
var bootstrap = require(__dirname + '/../src/bootstrap');
        _createAccount(bootstrap.app.dao, function() {
          process.exit(0);
        });
      });
    });

    dao.on('error', function(err) {
      console.log('MongoDB unconnectable via : ' + sparseConfig.dbMongo.connect);
      console.log(err);
      auxServers();
    });
  });
}

if (!fs.existsSync(targetConfig)) {
  domainSelect();

} else {

  //process.HEADLESS = true;
  var bootstrap = require(__dirname + '/../src/bootstrap');
  bootstrap.app.dao.on('ready', function() {

    bootstrap.app.dao.registerModel(require('../src/models/migration').Migration);

    bootstrap.app.dao.runMigrations(pkg.version, targetConfig, function(err, result) {
      if (err) {
        console.error(err);
      } else {
        console.log(result);
      }
github capitalone / oas-nodegen / lib / writer.js View on Github external
function deleteFolderRecursive(path, preventDeletion) {
  var canRemove = true;

  if (fs.existsSync(path)) {
    var files = fs.readdirSync(path);

    files.forEach(function(file,index) {
      var curPath = path + "/" + file;

      for (var i=0; i

node-fs

node-fs is an extension to the original nodejs fs library, offering new functionalities.

MIT
Latest version published 11 years ago

Package Health Score

56 / 100
Full package analysis

Popular node-fs functions