How to merge two text TXT files together in Node.JS

Today it’s all about making TXT merging as easy as possible. We are not going to be doing any difficult coding, rather we will be shifting gears to implement an API instead, one that will take care of the task for us. Let’s take a look.

Install the client first using this reference for our package.json file.

"dependencies": {
"cloudmersive-convert-api-client": "^2.1.6"
}

From here we can call our function, like so:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.MergeDocumentApi();var inputFile1 = "/path/to/file"; // File | First input file to perform the operation on.var inputFile2 = "/path/to/file"; // File | Second input file to perform the operation on (more than 2 can be supplied).var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.mergeDocumentTxt(inputFile1, inputFile2, callback);

To finish, we simply input our files to be merged together. That’s it! Just think about all the time you just saved.

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store