gulp replace task not working

I am building an Ionic App with AngularJS and i have a gulp task that should replace data in a file. The task executes without errors but it doesnt replace the data it is meant to replace. Its like nothing executed.

gulp.task('replace', function () {  
  // Get the environment from the command line
  var env = args.env || 'localdev';

  // Read the settings from the right file
  var filename = env + '.json';

  var settings = JSON.parse(fs.readFileSync('./config/' + filename, 'utf8'));
  console.log(settings.apiUrl)
// Replace each placeholder with the correct value for the variable.  
  gulp.src(paths.replace)  
    .pipe(replace({
      patterns: [
        {
          match: 'apiUrl',
          replacement: settings.apiUrl
        }
      ]
    }))
  .pipe(gulp.dest('./js/services'));
  console.log("here")
});

js/constants.js file

angular.module('loanstreet.constants',[])   
    .constant('apiUrl', '@@apiUrl');

localdev.json

{
  "apiUrl":"http://10.0.3.2:3000"
}

Upon replacing the apiUrl value, it should create and send to the destination .js/services/constants.js but it also doesnt create that as well.

Any recommendations because I honestly cant see what is wrong with the code. Any help appreciated.

I believe you should change the line:

gulp.src(paths.replace) 

To:

gulp.src('./js/constants.js') 

Or otherwise tell us what value paths.replace has at this moment.

Assuming you're using gulp-replace, the parameter you're using is wrong.

It should be replace(pattern, replacement)

Also I think the match value is wrong in your example. It will replace the key and value. You need the @@ in the matcher.

Change it to

.pipe(replace('@@apiUrl', settings.apiUrl))

If you need to replace multiple things then chain more calls to replace()

.pipe(replace('@@apiUrl', settings.apiUrl))
.pipe(replace('@@another', 'foo'))
.pipe(replace('@@more', 'bar'))