I am trying to create a datascraper using node. Here is a sample html code for an item that I am trying to scrape: Here is some code that I am using to extract: I was wondering if there was anyway I could get the text of ‘Todd’ and [Stack] using this query selector. I do not know what I
Tag: node.js
Is there a way to use static method with dependency injection in NestJS?
An example is better than a long explanation: How can I replace BakeryService.myStaticMethodToGetPrice() to use dependency injection, so I can test things easily for example? Answer Static methods cannot use dependency injection. This is because the idea of dependency injection (at least to Nest) is to inject…
Why does setTimeout still work when using an Express app?
I am making an Express app and I was going to use setTimeout to invalidate the access token used with a third party API after a set amount of time. I thought that it might not work, since async functions like setTimeout are pushed onto the event queue and don’t run until everything else is done running.…
Webpack can’t resolve @import of scss/css
I have a main Stylesheet style.scss, which I imported in my main JavaScript file script.js: This works great, and I could build my website that way in dev mode. Now I wanted to try and use separate Stylesheet and import them in my main stylesheet with the @import rule, like so: But now I get this error messag…
Puppeteer Cannot read property getElementById of undefined
I’m trying to pass a value to the browser created by the puppeteer, but this error appears: Cannot read property ‘getElementById’ of undefined The error is in this line: what am I doing wrong? Thanks. Answer You can only use getElementById in the page context. Use page.evaluate, eg: ThatR…
error when a non bot member comes online (presenceUpdate)
I am trying to get my bot to send this message when a bot goes online or offline. it works sometimes but when a human member comes online i get this error: UNCAUGHT EXCEPTION TypeError: Cannot read property ‘user’ of undefined. My code: Answer If we assume that this code is server side: Definitely…
Cast to ObjectID failed – mongoose
Hi I am trying to add an event to a users profile once they click on the event. I am getting the following error – Cast to ObjectId failed for value “{ event: ‘600066640807165d042b91dd’ }” at path “event”. The route for creating a profile and for creating an event wor…
How to make Node and React app to share classes
I’m building a Node and React app, both using TypeScript. Its directories tree is as follows: My question: Since I’m using the same language for both stacks, and in the future the React Native will be added also using TypeScript, I wonder how I can create one group of classes to be used for all of…
Unexpected field access control behaviour in KeystoneJS
I am attempting to apply field level access logic in KeystoneJS, as per these instructions. The following hides a field fieldName from the admin UI: But the field is not hidden from the admin UI if I use an imperative approach. See below, which I would expect to produce the same result as the static approach …
How to automate the creation of multiple ejs files with nodejs
I am currently making a blog site and I have this “compose page” where I can write articles. I’m currently using ejs so when the article is posted the data gets saved. But these articles are accessed on one ejs file only. Here is my code for some context: But I want my app.js to make a new e…