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

296
Views
How can I open an Image file using fs in NodeJS?

In my current codes, it does only can read a text file, How can I make an Image (base64) file opened with Photos Application (Windows)? Is there any chance to do that? If it's impossible, please let me know!

const fs = require('fs')

fs.readFile('./Test/a.txt', 'utf8' , (err, data) => {
    if (err) {
      console.error(err)
      return
    }
    console.log(data)
    return
})
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Another possible solution is like this:

const cp = require('child_process');

const imageFilePath = '/aaa/bbb/ccc'

const c = cp.spawn('program_that_opens_images',[
 `"${imageFilePath}"`
]);  


c.stdout.pipe(process.stdout);  
c.stderr.pipe(process.stderr);


c.once('exit', exitCode => {    
   // child process has exited

});
about 4 years ago · Juan Pablo Isaza Report

0

Do something like this:

const cp = require('child_process');
const c = cp.spawn('bash');  // 1

const imageFilePath = '/aaa/bbb/ccc'

c.stdin.end(` 
   program_that_opens_images "${imageFilePath}"
`);  // 2

c.stdout.pipe(process.stdout);  // 3
c.stderr.pipe(process.stderr);

c.once('exit', exitCode => {    // 4
   // child process has exited

});

what it does:

  1. spawns a bash child process (use sh or zsh instead if you want)
  2. writes to bash stdin, (inputting the command to run)
  3. pipes the stdio from the child to the parent
  4. captures the exit code from the child
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!