CodeX-API icon indicating copy to clipboard operation
CodeX-API copied to clipboard

How do I get stdin input with javascript?

Open wildcatco opened this issue 2 years ago • 0 comments

const input = require('fs').readFileSync('/dev/stdin').toString().split(' ');
console.log(Number(input[0]) + Number(input[1]));

With this code, I get error "node:internal/fs/utils:344\n throw err;\n ^\n\nError: ENXIO: no such device or address, open '/dev/stdin'\n at Object.openSync (node:fs:585:3)\n at Object.readFileSync (node:fs:453:35)\n at Object. (/app/codes/10609b19-df6a-4e33-8cc6-f31183eb3f29.js:1:29)\n at Module._compile (node:internal/modules/cjs/loader:1101:14)\n at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)\n at Module.load (node:internal/modules/cjs/loader:981:32)\n at Function.Module._load (node:internal/modules/cjs/loader:822:12)\n at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)\n at node:internal/main/run_main_module:17:47 {\n errno: -6,\n syscall: 'open',\n code: 'ENXIO',\n path: '/dev/stdin'\n}\n"

How can i access to stdin in javascript?

wildcatco avatar Feb 17 '23 12:02 wildcatco