Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

258
Views
How to get file extension from file content using Node.js

I need some help. I need to fetch what the file type should be from the file containing only using Node.js. I am explaining the scenario below.

Let's say I have some content like below.

let fileContent = "The textContent property sets or returns the text content of the specified node, and all its descendants."

As we can see here the variable fileContent has some text data and I want to write this data into one file. So for that, I need to create the file with a proper extension like abc.txt. Similarly, If fileContent has some json data then I will create the file like abc.json and write the value inside it.

So here I need to fetch what should be the type of file from this content only using Node.js. If anybody has a solution for this will be a great help.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use popular file-type package for this. You can send buffer/file/stream/blob as an input and get file type as an output.

const FileType = require('file-type');
...
const { ext, mime } = await FileType.fromBuffer(your_data);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!