Executing node-jq throws an event.js error - node.js

i created a node application which is used to take a log file in json format and after processing the data, we create a csv file. i am using the following packages in the app
"dependencies": {
"bluebird":"^3.7.2",
"js-yaml":"^4.1.0",
"json2csv":"^5.0.6",
"node-jq": "^1.12.0",
"yargs": "^17.0.1"
}
The app has been working properly for last 6 months and there has been no change in code. We did a scheduled deployment 5 days back and since then it does not generate the report and we get this error when we try to generate the file.
events.js:377
throw er; // Unhandled 'error' event
^
Error: spawn C:\reporting-app\node_modules\node-jq\bin\jq ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:274:19)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:82:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:280:12)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
errno: -4058,
code: 'ENOENT',
syscall: 'spawn C:\\reporting-app\\node_modules\\node-jq\\bin\\jq',
path: 'C:\\reporting-app\\node_modules\\node-jq\\bin\\jq',
spawnargs: [
'--slurp',
'[ .[] .logs[] ] | map(select(.context.recordID != "12345")) | unique_by(.context.ID) | map(select(.context.ID != null)) | map({ ID: .context.ID, timestamp: .timestamp, kiosk: .context.recordID, appTransactionId: .context.appTransactionId })'
]}
I think the error comes when we try to use node-jq.run method (see below)
execute(source) {
return jq.run(this.query, source, {
input: 'string',
slurp: true,
});
}
Any help in this regard would be appreciated.

I dont know exactly what the problem was but I tried downgrading the version of node.js to an older version (which was used when the app was built and deployed). I deleted node_modules and package-lock.json files. Did an npm install and the the app started working locally. I promoted the package-lock.json files to the server and the server started working too.
I have a subsequent question. For last 5 months there was no change in the code. Not even package or package-lock.json files. However we did an npm install everytime we generated the report using this app. The dev ops say they did not update the node version on the server. Any one knows how this downgrade of node may have solved the problem?

Related

nodejs how to get mongodb backup using application

I am working on a project that requires MongoDb backup after a certain period of time. The project is being built over MongoDB, Express as backend technologies with nodejs.
app is running on vercel and localhost. i want to get the backup from the application only.
i want to get the db backup using the application daily (i know about cron but i am stuck in backup part).
how can i get the mongodb backup using the nodejs application ?
i tried using the following code to get the backup (on my local host which is a windows) but failed :
const { spawn } = require('child_process')
const child = spawn('mongodump', [
`--db=${DB_NAME}`,
`--archive=${ARCHIVE_PATH}`,
'--gzip'
])
the error:
node:events:491
throw er; // Unhandled 'error' event
^
Error: spawn mongodump ENOENT
at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
at onErrorNT (node:internal/child_process:478:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (node:internal/child_process:289:12)
at onErrorNT (node:internal/child_process:478:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -4058,
code: 'ENOENT',
syscall: 'spawn mongodump',
path: 'mongodump',
spawnargs: [
'--db=store',
'--archive=C:\\tmp\\5484689.tar',
'--gzip'
]
}
i tried to solve the error but i couldnt and then now im trying to find a new way to get the mongodb backup on both localhost and vercel using the nodejs application.
and then i want to push the mongodb backup to minio s3.

"vitest --ui" causing "Error: spawn xdg-open ENOENT"

I'm trying to check out Vitest's fancy UI server in my node docker container. But can't get it up and running. When running the npm script vitest --ui I get a node error spawn xdg-open ENOENT.
Here the full error message:
$ npm run test-ui
> wpvite#0.0.0 test-ui
> vitest --ui
DEV v0.23.4 /home/node/apps/main/frontend
UI started at http://localhost:51204/__vitest__/
node:events:491
throw er; // Unhandled 'error' event
^
Error: spawn xdg-open ENOENT
at ChildProcess._handle.onexit (node:internal/child_process:283:19)
at onErrorNT (node:internal/child_process:476:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
at ChildProcess._handle.onexit (node:internal/child_process:289:12)
at onErrorNT (node:internal/child_process:476:16)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn xdg-open',
path: 'xdg-open',
spawnargs: [ 'https://localhost:51204/__vitest__/' ]
}
Node.js v18.10.0
Google is no help at all - nothing related to Vitest even close. Also I'm obviously not a Node.js expert.
Even though the Node.js error message appears pretty cryptic to me, I still was lucky to use Ubuntu as my primary OS (beside macOS) which made me draw my attention to xdg-open in the error message - I occasionally use the command to open all kind of programs/apps on Ubuntu. Don't know why, but you need to have xdg-open installed on your system, to be able to run vitest --ui, even though it's neither mentioned in Vitest nor in Vite Github repos with a single word. Anyway for debian based containers it's:
apt install xdg-utils --fix-missing
Allthough this made the ENOENT error go away and the UI server starts up without errors, I still don't get to see the UI app due to some runtime-dom errors... I give it up. But maybe someone else finds the xdg-open info helpful.
UPDATE: It's working!
I just had to append /__vitest__/ to my proxied local url as clearly described in the docs:
"Then you can visit the Vitest UI at http://localhost:51204/__vitest__/"

node error when calling "yarn start" in an app created by create-react-app

I recently created a new project with create-react-app, installed all newest packages for an old create-react-app project (which was using react-scripts 3.4.1, and the new project is using 5.0.0) and copied the old code and asset files over. To my puzzlement, the new project throws an error whenever I call "yarn start"
Starting the development server...
node:events:498
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)
Emitted 'error' event on ClientRequest instance at:
at TLSSocket.socketErrorListener (node:_http_client:442:9)
at TLSSocket.emit (node:events:520:28)
at TLSSocket.emit (node:domain:475:12)
at emitErrorNT (node:internal/streams/destroy:164:8)
at emitErrorCloseNT (node:internal/streams/destroy:129:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -54,
code: 'ECONNRESET',
syscall: 'read'
}
Node.js v17.4.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
For what it's worth, the old project doesn't throw an error despite that the src code is the same. The only difference is the packages.
I googled around and followed various advice, including this one: https://medium.com/#premal.katigar/how-to-fix-throw-er-unhandled-error-event-30172323a973. All to no avail.
There are a couple of clues that could be useful:
I use an antd landing page, which is basically a bunch of .jsx and .less files that constructs a page. If I replace that landing page code with some simple jsx component, e.g. something that simply returns an h1 tag, then there is no longer this node error. Yarn start would start the project fine.
The only differences between the old project that starts fine even with the aforementioned antd landing page, and the new one that throws the above error are that 1) the new project contains all the newest versions of the required packages, since I used "yarn install" for all the required packages 2) since I'm using the newest version of antd, instead of using "customize-cra", "react-app-wired", "babel-plugin-import" and "less-loader", I was simply using "craco-less". So the old project's "yarn start" actually called "react-app-rewired start" and the new one actually called "craco start".
I also tried downgrading node version from 17 to 16, and the error remained.
Any clue what might be the issue?

Error on running command to build app with AndroidJS

Im getting the next error when trying to build in debug a androidjs app I will show u all commands, cause is not to much, im using the docs so I create a app, then try to build.
This first part when i open the shell and create the project, cheking node first
Copyright (C) Microsoft Corporation. Todos los derechos reservados.
Prueba la nueva tecnologĂ­a PowerShell multiplataforma https://aka.ms/pscore6
PS C:\Users\Dani\proyectos> node -v
v14.15.1
PS C:\Users\Dani\proyectos\android> androidjs init
? Application name: app_template
? Project type: webview
$cd app_template
$npm install
$npm run start:dev
$npm run build
And not when im tying to build
PS C:\Users\Dani\proyectos\android> cd .\app_template\
PS C:\Users\Dani\proyectos\android\app_template> androidjs build -f
copying assets ...
updating app name...
Setting app version ...
Version Code: 1000032
Version Name: 1.0.0
updating theme ...
Using SDK: 2.2.0
Building Apk ...
events.js:292
throw er; // Unhandled 'error' event
^
Error: spawn java ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
at onErrorNT (internal/child_process.js:465:16)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
at onErrorNT (internal/child_process.js:465:16)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
errno: -4058,
code: 'ENOENT',
syscall: 'spawn java',
path: 'java',
spawnargs: [
'-jar',
'C:\\Users\\Dani\\AppData\\Roaming\\npm\\node_modules\\androidjs-builder\\build_tools\\apktool.jar',
'b',
'C:\\Users\\Dani\\.androidjs\\cache\\androidjs-sdk',
'-o',
'C:\\Users\\Dani\\.androidjs\\cache\\app_template.apk',
'--frame-path',
'C:\\Users\\Dani\\.androidjs\\cache'
]
}```
Any idea?
I realized I didn't have Java installed on local.

Node.JS, node-imagemagick: Invalid paramaters/ENOENT on function call

I am writing Node.js script to create thumbnails with imagemagick. I running Windows 10. I have installed the latest Windows Binary release of ImageMagick, selecting the options to add it to the path and install legacy utilities (e.g., convert). I am using node-imagemagick to interface with ImageMagick from my script.
I can successfully use ImageMagick from the command line. For example, if I run the following command convert C:/Users/Admin/Desktop/in.jpg -resize 150x150 C:/Users/Admin/Desktop/out.jpg ImageMagick will create a thumbnail. However, if I run the convert function with the same arguments in my Node.js script:
var im = require('imagemagick');
im.convert(['C:/Users/Admin/Desktop/in.jpg', '-resize', '150x150', 'C:/Users/Admin/Desktop/out.jpg'], function (err, stdout) {
if (err) throw err;
console.log('stdout:', stdout);
});
Returns an error
Error: Command failed: Invalid Parameter - /Users
at ChildProcess.<anonymous> (C:\Users\Admin\Documents\Projects\node_script\node_modules\imagemagick\imagemagick.js:88:15)
at ChildProcess.emit (events.js:311:20)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5) {
timedOut: false,
killed: false,
code: 4,
signal: null
}
In case this was because of the path separators being different on Windows, I tried replacing the slashes with double backslashes and surrounding the paths in quotes ['"C:\\Users\\Admin\\Desktop\\in.jpg"',.... However, I instead get the error Error: Command failed: Invalid Parameter - -resize.
This also happens with the identify command. identify -format %[EXIF:*] C:/Users/Admin/Desktop/in.jpg sucussfully returns information about my image while my Node.js script:
im.identify(['identify', 'C:/Users/Admin/Desktop/in.jpg'], function(err, features){
if (err) throw err;
console.log(features);
});
Returns an error
Error: spawn identify ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn identify',
path: 'identify',
spawnargs: [ 'identify', 'C:/Users/Admin/Desktop/in.jpg' ]
}
If these errors are not correctable or are unnecessarily hard to correct, is there a better way to create thumbnails in Node.js? I will eventually need to be able to generate thumbnails for videos and .swf files. The last publish of node-imagemagick was 7 years ago, is there anything more recent?
There is a much better alternative and actively maintained solution to node-imagemagick called sharp.
Usage (based on your question):
const sharp = require('sharp');
sharp('C:/Users/Admin/Desktop/in.jpg')
.resize(150, 150)
.toFile('C:/Users/Admin/Desktop/out.jpg')
.then(outputInfo => {
console.log(outputInfo);
})
.catch(reason => {
console.log(reason);
});
Found a comment saying to restart your device if using node imagemagick with Windows. After a restart commands called from the Node.js script worked without errors.

Resources