Update string in a file - Node.js File

Node.js examples for File:Text File

Description

Update string in a file

Demo Code


var file = require('fs');

String.prototype.capitalize = function() {
  return this.charAt(0).toUpperCase() + this.slice(1);
}

file.readFileSync(process.argv[2]).toString().split('\n').forEach(function(line) {
  var words = line.split(' ');
  var sentence = [];  
  for (i = 0; i < words.length; i++) {
    sentence.push(words[i].capitalize());
  }//from   w w w  . ja  v  a2s .  c om
  console.log(sentence.join(' '));
});

Related Tutorials