Nodejs GM module ImageMagick - strange Error - node.js

I have a very strange error. I'm using MAC OS X 10.9.5.
When i use some functions from GM (npm install gm) like resize or something else i got this error.
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:988:11)
at Process.ChildProcess._handle.onexit (child_process.js:779:34)
I have found many threads about it and according to them i have installed graphicksmagic and imagemagick with brew to system.
brew install imagemagick
brew install graphicsmagick
It was working for a while but for no reason it starts to showing the above error again.
I checked that i have installed imagemagick and graphicksmagick in system and its working from terminal.
I checked if i have it in $PATH and its there.
If i run this in nodejs it shows correct version of imagemagick in console, so i assume path is ok in nodejs.
var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) {
if(error)
sys.puts(error);
if(stderr)
sys.puts(stderr);
sys.puts(stdout);
}
exec("identify --version", puts);
This is code which is crashing:
gm(request(url), thumbName)
.resize('300', '300', '^')
.gravity('Center')
.crop('300', '300')
.toBuffer('JPG',function (err, buffer) {
var data = {
Bucket: bucket,
Key: thumbName,
Body: buffer,
ACL:'public-read',
ContentType: 'image/jpeg'
};
s3.putObject(data, function(err, res) {
....
});
Everything is working when i deploy it on heroku

IF someone will have this issue i solved it.
I add variable PATH to enviroment variables in node with this value
bin:node_modules/.bin:/usr/local/bin:/usr/bin:/bin

Related

How to test an node file, receiving an 'EACCES' error when spawning the function

When creating a CLI I would like to test my function. For that I'm using the module child_process.
const path = require('path');
const { execFile } = require('child_process');
describe('cli test', () => {
test('thing', () => {
const myCli = execFile(
`${path.resolve(__dirname, '..')}/cli.js`, ['--foo', 'Bar'],
(err, stdout, stderr) => {
if (err) {
console.log('err: ', err);
}
});
});
But this produces the following error:
Attempted to log "err: { Error: spawn /projects/cli/src/cli.js EACCES
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
errno: 'EACCES',
code: 'EACCES',
Running this script directly in the terminal via the command: $ node cli.js --foo Bar works perfectly.
Now a suggestion is to chmod +x <file> that file (source). But the test should also work on CI, and on a different computer which pulls the Git repo.
Any idea?
I'd suggest using fork instead of execFile.
The child_process.fork() method is a special case of child_process.spawn() used specifically to spawn new Node.js processes.
This will allow you to execute JS files without needing them to be shell executable.
To the best of my knowledge, git actually tracks the executable bit for files. There are some things to consider though as pointed out in this article: https://medium.com/#tahteche/how-git-treats-changes-in-file-permissions-f71874ca239d
Another solution would be to not rely on the ./ execution syntax (which requires the executable bit to be turned on for the respective file) but instead to explicitly use the shell command:
const path = require('path');
const { execFile } = require('child_process');
describe('cli test', () => {
test('thing', () => {
const myCli = execFile(
`sh ${path.resolve(__dirname, '..')}/cli.js`, ['--foo', 'Bar'],
(err, stdout, stderr) => {
if (err) {
console.log('err: ', err);
}
});
});
Notice the sh prefix I added to your code, This way you thell the sh command (which should be available in all of your environments e.g. the CI) to execute the contents of the file, regardless of whether the file itself can be executed or not!
I was receiving an EACCESS -13 error from child_process.spawn when trying to run a the command line mysql command.
There was something wrong with my PATH and updating it to add /usr/local/mysql/bin/ resolved the problem.
The temporary fix is to run export PATH=$PATH:/usr/local/mysql/bin/.
The permanent fix is to:
type: sudo nano /etc/paths
Add /usr/local/mysql/bin at the end
Ctrl + X
Yes
Enter key
type hash -r # command line or close the terminal app and open it again
NOTE: I got the temporary fix from a site ... I don't know why it has a / on the end of the bin but all of the mysql executables appear to be available without it in the /etc/paths file

Random occurrences of Failed: ECONNREFUSED connect ECONNREFUSED 127.0.0.1 when running protractor tests

My protractor test cases randomly fail with this error message:
Failed: ECONNREFUSED connect ECONNREFUSED 127.0.0.1
I have gone through the resources and tried all the suggested solutions:
Upgraded protractor
Ran webdriver-manager update
Upgraded chromedriver version but the issue seems to exist.
This particularly happens when I try to run all the e2e tests together.
Below is the specific versions that Im using for my project:
node - v9.2.0
protractor - Version 5.4.1
ChromeDriver 2.42.591088
Please help.
Thanks,
Neeraja
Are you using async/await in your tests?
Can you try applying patch as specified below from the same folder which contains the 'node_modules' folder by executing 'node patch.js'?
patch.js file
var fs = require('fs');
var httpIndexFile = 'node_modules/selenium-webdriver/http/index.js';
fs.readFile(httpIndexFile, 'utf8', function (err, data) {
if (err)
throw err;
var result = data.replace(/\(e.code === 'ECONNRESET'\)/g, "(e.code === 'ECONNRESET' || e.code === 'ECONNREFUSED')");
console.log(`Patching ${httpIndexFile}`)
fs.writeFileSync(httpIndexFile, result, 'utf8');});
var chromeFile = 'node_modules/selenium-webdriver/chrome.js';
fs.readFile(chromeFile, 'utf8', function (err, data) {
if (err)
throw err;
var result = data.replace(/new http.HttpClient\(url\)/g, "new http.HttpClient(url, new (require('http').Agent)({ keepAlive: true }))");
console.log(`Patching ${chromeFile}`)
fs.writeFileSync(chromeFile, result, 'utf8');});
Please see original post here -
https://github.com/angular/protractor/issues/4706#issuecomment-393004887

cannot find ffmpeg in videoshow in nodejs

I want to create video from image files. So I have installed videoshow module. And configured the same as per the documentaion.
var videoOptions = {
fps: 25,
loop: 5, // seconds
transition: true,
transitionDuration: 1, // seconds
videoBitrate: 1024,
videoCodec: 'libx264',
size: '640x?',
audioBitrate: '128k',
audioChannels: 2,
format: 'mp4',
pixelFormat: 'yuv420p'
}
var images = [
"D:/PROJECTS/Video/storage/1.jpg",
"D:/PROJECTS/Video/storage/2.jpg"
];
app.get("/video", function () {
videoshow(images, videoOptions)
// .audio('song.mp3')
.save('video.mp4')
.on('start', function (command) {
console.log('ffmpeg process started:', command)
})
.on('error', function (err, stdout, stderr) {
console.error('Error:', err)
console.error('ffmpeg stderr:', stderr)
})
.on('end', function (output) {
console.error('Video created in:', output)
})
});
But When I run it shows the error on server
Error: Error: Cannot find ffmpeg
at D:\PROJECTS\Video\node_modules\videoshow\node_modules\fluent-ffmpeg\lib\processor.js:136:22
at D:\PROJECTS\Video\node_modules\videoshow\node_modules\fluent-ffmpeg\lib\capabilities.js:123:9
at D:\PROJECTS\Video\node_modules\videoshow\node_modules\async\dist\async.js:473:16
at next (D:\PROJECTS\Video\node_modules\videoshow\node_modules\async\dist\async.js:5315:29)
at D:\PROJECTS\Video\node_modules\videoshow\node_modules\async\dist\async.js:958:16
at D:\PROJECTS\Video\node_modules\videoshow\node_modules\fluent-ffmpeg\lib\capabilities.js:116:11
at D:\PROJECTS\Video\node_modules\videoshow\node_modules\fluent-ffmpeg\lib\utils.js:223:16
at F (D:\PROJECTS\Video\node_modules\videoshow\node_modules\which\which.js:68:16)
at E (D:\PROJECTS\Video\node_modules\videoshow\node_modules\which\which.js:80:29)
at D:\PROJECTS\Video\node_modules\videoshow\node_modules\which\which.js:89:16
Then I installed ffmpeg using
npm install ffmpeg --save
but not worked. So I tried installing at the global level using
npm install ffmpeg -g
Even installing on my window machine and setting the path of its bin folder in environment variables did not work?
What could be the issue?
Actually, I need to instal the ffmpeg in my system and set it to the environment path variable.
And you don't need to install in nodejs.
npm i videoshow
Just use this command

node.js: Error: Cannot find module

Why do I get this error?
Node v8.9.1
code
var childProcess = require('child_process'),
phantomjs = require('/var/bin/node_modules/phantomjs-prebuilt');
console.error = function(){
require('system').stderr.write(Array.prototype.join.call(arguments, ' ')+'\n');
phantomjs.exit(1);
};
console.log('hey', phantomjs.path)
console.error('error')
childProcess.execFile(phantomjs.path, require('system').args, function(err, stdout, stderr){
if(err){
console.error(err);
}
if(stderr){
console.error(stderr);
}
console.log(stdout);
});
error
# /var/bin/node_modules/phantomjs-prebuilt/bin/phantomjs phantom.js
Error: Cannot find module 'path'
phantomjs://platform/bootstrap.js:299 in require
phantomjs://platform/bootstrap.js:263 in require
phantomjs://platform/phantomjs.js:10
hey undefined
TypeError: undefined is not a function (evaluating 'phantomjs.exit(1)')
phantomjs://code/phantom.js:6 in error
error
system is not a Node built-in module, it's part of PhantomJS. It won't be available if you're just running your script with the standard node command. As shown in the documentation, you need to use the phantomjs command, like so:
phantomjs phantom.js

imagemagick: running into Error: write EPIPE when passing in a buffer object

Currently writing a node-based utility based on the node imagemagick library to take in a stream and output another stream to STDOUT:
im = require('imagemagick')
request = require("request")
sampleImage = "http://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg"
request.get(sampleImage, (err, res, body) ->
prefix = "-"
switch (res.headers['content-type'])
when "image/jpeg"
prefix = "jpg:-"
when "image/png"
prefix = "png:-"
taskHash = {
srcPath: prefix
srcData: body
dstPath: -
height: 100
}
callback = (err, stdout, stderr)->
if err
console.error(err)
process.exit(1)
console.log(stdout)
im.resize(taskHash, callback)
)
Getting the following error:
events.js:72
throw er; // Unhandled 'error' event
^
Error: write EPIPE
at errnoException (net.js:904:11)
at Object.afterWrite (net.js:720:19)
Have noticed a similar error discussed here, but I think that this is a separate case, since I'm not using the graphicsmagick library. Is it not possible to use buffers without installing both imagemagick and graphicsmagick?
node-imagemagick require two things:
Node.js
ImageMagick ;)
You have to install missing library (e.g. for Ubuntu):
sudo apt-get update
sudo apt-get install imagemagick --fix-missing
It will solve your problem

Resources