node.js - image-watermark, nodejs showing error -


i trying put watermark on image, using image-watermark, nodejs.

const express = require('express')     const app = express();     var path = require('path');     var watermark = require('image-watermark');        app.use(express.static(path.join(__dirname, 'public')));  var options = {     'text' : 'sample watermark',      'resize' : '200%' };  app.get('/', function (req, res) {     var fs = require('fs');     if (fs.existssync('./public/files/pg363.jpg')) {         //         watermark.embedwatermark('./public/files/pg363.jpg', options);         res.send('hello world');     }else{         res.json({"filesexist":"no"});     }  });   app.listen(3000,function(){     console.log('app running on server 3000'); }) 

this giving me error:

    events.js:163       throw er; // unhandled 'error' event       ^  error: spawn identify enoent     @ exports._errnoexception (util.js:1050:11)     @ process.childprocess._handle.onexit (internal/child_process.js:193:32)     @ onerrornt (internal/child_process.js:367:16)     @ _combinedtickcallback (internal/process/next_tick.js:80:11)     @ process._tickcallback (internal/process/next_tick.js:104:9) 

is error related filepath. directory structure pdf-watermark(home directory)-> public-> files-> pg363.jpg

please help.

enoent means node can't open file reason, caused few things.

firstly, should specify full path image file, using path.resolve , __dirname:

const imagepath = path.resolve(__dirname, 'public/files/pg363.jpg'); if (fs.existssync(imagepath)) {     watermark.embedwatermark(imagepath, options);     // ... } 

secondly, should make sure node running user appropriate read/write permissions update image file.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -