why child process not support query session - node.js

hello guys I search a lot on the internet as well as I tried the below thing but this does not work I don't know why
const exec = require('child_process');
let p = exec.execSync("query session").toString();
can anyone tell me why the above line "query session" is not working other than this eg "tasklist","whoami" etc everything working fine
error throw like show below:
Error: Command failed: query session rpa-agent1
at checkExecSyncError (child_process.js:629:11)
at Object.execSync (child_process.js:666:13)
at TestScreen.execute (C:\Users\Public\production_rpa_agent\action-
paths\testscreen\index.js:39:21)
at Object.<anonymous> (C:\Users\Public\production_rpa_agent\action-paths\testscreen\index.js:67:4)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
query session is a window command used for getting rdp login user.

Related

Syntax error on "=" NodeJs in Ubuntu 20.04

I have developed a NodeJs(v10.19.0) server on windows.
I now need to transfer it to a linux server running Ubuntu 20.04
When I try to start the server, I have a syntax error on a "=".
Here's the complet error:
/puppeteer/scraping-bot.js:6
static websiteRegex = /^(https?\:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})(\/[\w\W]*)*$/gm
^
SyntaxError: Unexpected token =
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (/routes/scraping.js:1:21)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
[nodemon] app crashed - waiting for file changes before starting...
Here's the code that outputs the error:
class ScrapingBot {
static websiteRegex = /^(https?\:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})(\/[\w\W]*)*$/gm
static phoneRegex = /\+?\d{1,4}?[-.\s]?\(?\d{1,3}?\)?[-.\s]?\d{1,4}[-.\s]?\d{1,4}[-.\s]?\d{1,9}/g;
static addressRegex = /(([a-zA-Z-éÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ'.]*\s)\d*(\s[a-zA-Z-éÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ']*)*,)*\d*(\s[a-zA-Z-éÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ']*)+,\s([\d]{5})\s[a-zA-Z-éÉèÈàÀùÙâÂêÊîÎôÔûÛïÏëËüÜçÇæœ']+/
...
}
I set up Git with nano if that helps...
I have already tried to replace the "=".
As you can see in here, static class fields are not supported as of Node 10 ->
https://node.green/#ES2022-features-static-class-fields
edit: #jonrsharpe also answered this

app.use(express.urlencoded({extended:false})) throws error on submit

I had to submit a form containing few parameters from localhost:2000/articles/new. I put the form method and action as <form action="/articles" method="POST">.
My post function is in article route and is like this:
router.post("/", (req, res) => {
console.log("sent")
console.log(req)
res.end()
})
My server.js file contains app.use("/articles", articleRouter)
I have used app.use(express.urlencoded({extended:false})) in server.js file
Now problem arises here:
==> when I use the app.use(express.urlencoded({extended:false})) I get error on submitting form.
The error I got is below:
C:\blog\node_modules\iconv-lite\encodings\dbcs-codec.js:1
SyntaxError: Invalid or unexpected token
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\blog\node_modules\iconv-lite\encodings\index.js:12:5)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.getCodec (C:\blog\node_modules\iconv-lite\lib\index.js:65:27)
at Object.getDecoder (C:\blog\node_modules\iconv-lite\lib\index.js:127:23)
==>But when I don't use it and submit the form the console.log of post function (router.post function ) works. I do not know what is the problem here please help me.
PROBLEM SOLVED FOR ME
I simply deleted node modules folder and again ran npm i on cmd.
This reinstalled all my node modules and its file, now it is working for me.

ReferenceError: require is not defined (node.js)

I'm trying to run a node.js script from my node.js server. The problem is that the modules I import with require () do not work anymore while all the modules and files are in the same folder.
var mysql = require('mysql');
^
ReferenceError: require is not defined
at evalmachine.<anonymous>:3:13
at ContextifyScript.Script.runInThisContext (vm.js:25:33)
at Object.runInThisContext (vm.js:97:38)
at Object.<anonymous> (D:\wamp\www\node_server\test_server.js:8:14)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
Thank you in advance,
I had a similar problem - server-side nodejs thinking that require is not defined.
It turns out the line "type": "module" in my package.json was causing this error, and once I removed that require worked as expected.

Type Error: require(...) is not a function in SendGrid NodeJS

I am trying to send emails using the following doc on sendrid:
https://sendgrid.com/docs/Integrate/Code_Examples/v2_Mail/nodejs.html
My app.js looks like this:
var sendgrid = require('sendgrid')('SENDGRID_APIKEY');
When runnig npm start I get the following error:
var sendgrid = require('sendgrid')(conf);
^
TypeError: require(...) is not a function
at Object.<anonymous> (C:\Users\Grandullon\Desktop\angular\app.js:8:36)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (C:\Users\Grandullon\Desktop\angular\bin\www:7:11)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
Any ideas what I am doing wrong? conf is a variable where I store my API key.
I am using a clean express installation.
THANKS
My package.json can be looked here as requested:
http://pastebin.com/pGKWFReX
The latest documentation shows a different structure for initialization.
You should try doing
var sg = require('sendgrid').SendGrid(conf);

Code of nodejs using mongoose works on local machine but on VPS it doen't

This works on windows 7 localhost:
var User = mongoose.model(userDBName, userSchema);
But it gives this error for Debian VPS:
/home/node_modules/mongoose/lib/utils.js:28
return pluralize(name.toLowerCase());
^
TypeError: Cannot call method 'toLowerCase' of undefined
at exports.toCollectionName (/home/node_modules/mongoose/lib/utils.js:28:25)
at Mongoose.model (/home/node_modules/mongoose/lib/index.js:361:46)
at Object.<anonymous> (/home/XXX/nodejs/js/dbbase.js:54:21)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/XXX/nodejs/js/db_read.js:1:76)
How to fix it?
The error was the name is really undefined, due to userDBName is undefined. It relative with 'nconf' and config.json. Just incorrect way to this file.

Resources