Search code examples
javascriptnode.jsfs

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
})

Solution

  • Another possible solution is like this:

    const cp = require('child_process');
    
    const imageFilePath = '/aaa/bbb/ccc'
    
    const c = cp.spawn('a_program_that_opens_images', [ `"${imageFilePath}"` ]);  
    
    
    c.stdout.pipe(process.stdout);  
    c.stderr.pipe(process.stderr);
    
    
    c.once('exit', exitCode => { 
    
       // child process has exited
    
    });