-
pister
- Posts: 52
- Joined: Thu Jun 21, 2018 5:24 pm
NodeJS writeStream ‘Einval’ error when running in crontab and chid process
Hi everyone, I have the following two files (there is more but I have stripped back)
Code: Select all
//File A:
cron.schedule('0 1 * * *', () => {
childProcess.fork('fileB.js')
});
Code: Select all
//File B:
for (var i in array) {
const file = fs.createWriteStream(`${i}.jpg`);
const request = http.get(`https://randomUrl.com/${i}.jpg`, async function(response) {
await response.pipe(file);
}
}
When running file b in isolation, it runs through the whole array every time. However, when used with file A, it will run for a seemingly random number of results before firing the error:
events.js:291
throw er; // Unhandled ‘error’ event
^Error: EINVAL: invalid argument, open ‘my path goes here»
Emitted ‘error’ event on WriteStream instance at:
at internal/fs/streams.js:361:12
at FSReqCallback.oncomplete (fs.js:156:23) {
errno: -22,
code: ‘EINVAL’,
syscall: ‘open’,
path: ‘my path goes here’
}
Any help would be appreciated as I am honestly stumped. Thanks
-
Heater
- Posts: 19296
- Joined: Tue Jul 17, 2012 3:02 pm
Re: NodeJS writeStream ‘Einval’ error when running in crontab and chid process
Thu Mar 24, 2022 8:05 am
No idea but can I suggest you check for errors from all those functions you are calling.
The example here https://nodejs.org/en/knowledge/advance … te-stream/ shows how to catch errors, and other events, from createWriteStream(). Here https://nodejs.dev/learn/making-http-re … ith-nodejs we see an example of handling errors from https request.
The errors you detect will likely tell you what the problem is immediately.
Note that your script will be writing files into whatever directory you are in when you run it. Likely the same directory as the script. When run from cron who knows what directory it will be writing into. You should give the full path of the file to write to ‘createWriteStream’.
In general when programming always check all errors. This is even more important with a language like JS. Otherwise you will always be hopelessly lost when things start to go wrong.
Slava Ukrayini.
-
pister
- Posts: 52
- Joined: Thu Jun 21, 2018 5:24 pm
Re: NodeJS writeStream ‘Einval’ error when running in crontab and chid process
Thu Mar 24, 2022 8:30 pm
Hi, thanks for your reply. When I get a moment I’ll have a look through. I have edited that code to remove the absolute paths. The ‘path goes here’ was just so there wasnt a massive long absolute path. Thanks again!
Return to “Other programming languages”
Environment
Windows 7 x64
Ionic v 5.4.8
Task
Error when running ionic serve in ionic project
E:ionicProject>ionic serve
> ng.cmd run app:serve –host=localhost –port=8100
[ng] i events.js:187
throw er; // Unhandled ‘error’ event
^
Error: write EIO
[90m at afterWriteDispatched (internal/stream_base_commons.js:150:25)[39m
[90m at writeGeneric (internal/stream_base_commons.js:141:3)[39m
[90m at WriteStream.Socket._writeGeneric (net.js:770:11)[39m
[90m at WriteStream.Socket._write (net.js:782:8)[39m
[90m at doWrite (_stream_writable.js:431:12)[39m
[90m at writeOrBuffer (_stream_writable.js:415:5)[39m
[90m at WriteStream.Writable.write (_stream_writable.js:305:11)[39m
at StreamHandler.handle (E:prograsandroidnode-v12.13.0-win-x64node_modul
es[4mionic[24mnode_modules[4m@ionic[24mcli-frameworkliblogger.js:53:21
)
at Logger.log (E:prograsandroidnode-v12.13.0-win-x64node_modules[4mion
ic[24mnode_modules[4m@ionic[24mcli-frameworkliblogger.js:147:21)
at Object._write (E:prograsandroidnode-v12.13.0-win-x64node_modules[4m
ionic[24mnode_modules[4m@ionic[24mcli-frameworkliblogger.js:154:22)
Emitted ‘error’ event on WriteStream instance at:
[90m at errorOrDestroy (internal/streams/destroy.js:108:12)[39m
[90m at onwriteError (_stream_writable.js:446:5)[39m
[90m at onwrite (_stream_writable.js:473:5)[39m
[90m at internal/streams/destroy.js:50:7[39m
[90m at WriteStream.dummyDestroy [as _destroy] (internal/process/stdio.js:7:
3)[39m
[90m at WriteStream.destroy (internal/streams/destroy.js:38:8)[39m
[90m at afterWriteDispatched (internal/stream_base_commons.js:150:17)[39m
[90m at writeGeneric (internal/stream_base_commons.js:141:3)[39m
[90m at WriteStream.Socket._writeGeneric (net.js:770:11)[39m
[90m at WriteStream.Socket._write (net.js:782:8)[39m {
errno: [32m’EIO'[39m,
code: [32m’EIO'[39m,
syscall: [32m’write'[39m
}
Solution:
Restart computer
При создании сборки для продакшена я все время получаю эту ошибку. У меня никогда не было проблемы до обновления до версии 12.0.0. Я попытался удалить файл, но он работает только тогда, когда сервер разработки не запущен, пока он работает, я не могу его открыть или удалить, и это приводит к сбою каждой производственной сборки.
info - Creating an optimized production build .events.js:291
throw er; // Unhandled 'error' event
^
Error: EPERM: operation not permitted, open 'D:etcssssss.nexttrace'
Emitted 'error' event on WriteStream instance at:
at D:etcssssssnode_modulesnextdistcompiled@vercelnftindex.js:1:287421
at D:etcssssssnode_modulesnextdistcompiled@vercelnftindex.js:1:287860
at FSReqCallback.oncomplete (fs.js:164:23) {
errno: -4048,
code: 'EPERM',
syscall: 'open',
path: 'D:\etc\ss\ss\ss\.next\trace'
}
1 ответ
Лучший ответ
Просто остановите npm run dev
, затем запустите npm run build
. Это сработало для меня.
20
Berci
11 Сен 2022 в 09:21
Javascript Online Compiler
Write, Run & Share Javascript code online using OneCompiler’s JS online compiler for free. It’s one of the robust, feature-rich online compilers for Javascript language. Getting started with the OneCompiler’s Javascript editor is easy and fast. The editor shows sample boilerplate code when you choose language as Javascript and start coding.
About Javascript
Javascript(JS) is a object-oriented programming language which adhere to ECMA Script Standards. Javascript is required to design the behaviour of the web pages.
Key Features
- Open-source
- Just-in-time compiled language
- Embedded along with HTML and makes web pages alive
- Originally named as LiveScript.
- Executable in both browser and server which has Javascript engines like V8(chrome), SpiderMonkey(Firefox) etc.
Syntax help
variable declaration
Keyword | Description | Scope |
---|---|---|
var | Var is used to declare variables(old way of declaring variables) | Function or global scope |
let | let is also used to declare variables(new way) | Global or block Scope |
const | const is used to declare const values. Once the value is assigned, it can not be modified | Global or block Scope |
Backtick Strings
Interpolation
let greetings = `Hello ${name}`
Multi line Strings
const msg = `
hello
world!
`
Arrays
An array is a collection of items or values.
Syntax:
let arrayName = [value1, value2,..etc];
// or
let arrayName = new Array("value1","value2",..etc);
Example:
let mobiles = ["iPhone", "Samsung", "Pixel"];
// accessing an array
console.log(mobiles[0]);
// changing an array element
mobiles[3] = "Nokia";
Arrow functions
Arrow Functions helps developers to write code in concise way, it’s introduced in ES6.
Arrow functions can be written in multiple ways. Below are couple of ways to use arrow function but it can be written in many other ways as well.
Syntax:
() => expression
Example:
const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const squaresOfEvenNumbers = numbers.filter(ele => ele % 2 == 0)
.map(ele => ele ** 2);
console.log(squaresOfEvenNumbers);
De-structuring
Arrays
let [firstName, lastName] = ['Foo', 'Bar']
Objects
let {firstName, lastName} = {
firstName: 'Foo',
lastName: 'Bar'
}
rest(…) operator
const {
title,
firstName,
lastName,
...rest
} = record;
Spread(…) operator
//Object spread
const post = {
...options,
type: "new"
}
//array spread
const users = [
...adminUsers,
...normalUsers
]
Functions
function greetings({ name = 'Foo' } = {}) { //Defaulting name to Foo
console.log(`Hello ${name}!`);
}
greet() // Hello Foo
greet({ name: 'Bar' }) // Hi Bar
Loops
1. If:
IF is used to execute a block of code based on a condition.
Syntax
if(condition){
// code
}
2. If-Else:
Else part is used to execute the block of code when the condition fails.
Syntax
if(condition){
// code
} else {
// code
}
3. Switch:
Switch is used to replace nested If-Else statements.
Syntax
switch(condition){
case 'value1' :
//code
[break;]
case 'value2' :
//code
[break;]
.......
default :
//code
[break;]
}
4. For
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
//code
}
5. While
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while (condition) {
// code
}
6. Do-While
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
Classes
ES6 introduced classes along with OOPS concepts in JS. Class is similar to a function which you can think like kind of template which will get called when ever you initialize class.
Syntax:
class className {
constructor() { ... } //Mandatory Class method
method1() { ... }
method2() { ... }
...
}
Example:
class Mobile {
constructor(model) {
this.name = model;
}
}
mbl = new Mobile("iPhone");