How to detect the Line Ending Type of a Text File in Node.JS

Cloudmersive
1 min readApr 21, 2020

--

We all know what we’re here for. For today, what do you say we skip the introduction and dive straight into how to get this done.

Our first step is the installation of our API client. This requires the following command for npm install.

npm install cloudmersive-convert-api-client --save

This prepares us for our function call, which we have below:

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 inputFile = "/path/to/file"; // File | Input file to perform the operation on.var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.editTextDetectLineEndings(inputFile, callback);

And now if you input your text files into editTextDetectLineEndings, you will be informed as to what operating system corresponds to your file’s line ending type.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet