Node.js req.query Not Defined in PhpStorm
I am making my first Node.js application using PhpStorm. It has gone great so far, but today I tried to get querystring parameters and noticed a squiggly line under req in req.query['param'] saying "Unresolved variable or type req" and when I tried to run the application I got:
ReferenceError: req is not defined
at Object.<anonymous> (C:\Users\me\PhpstormProjects\myprojectname\index.js:4:13)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
I have checked other threads and verified that I have coding assistance for Node.js enabled in Settings > Languages & Frameworks > Node.js and NPM. I also verified that the box is checked next to Node.js Core in Settings > Languages & Frameworks > JavaScript > Libraries.
The packages enabled so far are Puppeteer, rss-parser, and workbox-cli.
Please sign in to leave a comment.
the issue has nothing to do with the IDE, so setting up coding assistance won't help; this is a runtime error in your code.
Please share your code plus a command you use to run it
I found a way to get query string parameters, but I still can't pass a URL with parameters when running the app. When I try changing the URL from the file name to the file name plus some strings it always throws an error. How do I run an application with query strings appended to the file name?
Not sure I follow you... What does your application look like, what command do you use to run it? Query string can be passed when opening certain URL in browser/making HTTP request, you can also pass it as an argument to your Node app main function and then process it in your code somehow... It's not quite clear what you are trying to accomplish
Elena, I am trying to build an app that can be uploaded to a web server and receive parameters via the URL I have since ported my project to Visual Studio which included a default file that loads the app in a browser window, but even in that case it seems that I can't get the URL being loaded. I tried window.location.href but that results in an object promise error.
My end goal is to have something like https://mypuppeteerapp.com/app.js?&url=https://pagetocrawl.com&content-element=main which would lead to puppeteer copying the main element at that URL.
To load a js file in the browser, you need creating HTML file with this .js included via <script src="path/to/js"> tag, nothing more. Moving to this ot that IDE/editor won't help you unless you have an idea of what you are trying to do. Seems you need some basic web dev training, sorry.