How to replace a text string with another string value in Node.JS
1 min readApr 2, 2020
Today we are going to demonstrate how to set up a simple search and replace function for text strings using Node.JS. With a little help from an API, we will be done in no time at all.
We can use npm install to import our client, allowing access to our API functions.
npm install cloudmersive-convert-api-client --save
Now we are able to call editTextReplaceSimple:
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.EditTextApi();var request = new CloudmersiveConvertApiClient.ReplaceStringSimpleRequest(); // ReplaceStringSimpleRequest | Input requestvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.editTextReplaceSimple(request, callback);
Now just specify your strings and try it out. Super easy!