Error in my command line when i tried to run my node app.js

When i tried to run node app.js from my server. It brought the error below:

C:UsersBLUE HOSTDesktoptodolist-v1>node app.js
C:UsersBLUE HOSTDesktoptodolist-v1node_modulesexpresslibrouterindex.js:464
throw new TypeError(‘Router.use() requires a middleware function but got a ‘ + gettype(fn))
^

TypeError: Router.use() requires a middleware function but got a string
at Function.use (C:UsersBLUE HOSTDesktoptodolist-v1node_modulesexpresslibrouterindex.js:464:13)
at Function. (C:UsersBLUE HOSTDesktoptodolist-v1node_modulesexpresslibapplication.js:220:21)
at Array.forEach ()
at Function.use (C:UsersBLUE HOSTDesktoptodolist-v1node_modulesexpresslibapplication.js:217:7)
at Object. (C:UsersBLUE HOSTDesktoptodolist-v1app.js:6:5)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)

This is my app.js file:

const express = require("express");
const app = express();
app.use(express.urlencoded({extended: true}));
app.use("view engine", "ejs");

app.get("/",function(req,res) {
var today = new Date();
var currentDay = today.getDay();
var day = "";

if (currentDay === 6 || currentDay === 0) {
day = "weekend";
} else{
day = "weekday";
 }
 res.render("list", { kindOfDay: day });
});

app.listen(3000, function() {
console.log("Listening on port 3000");
});

This is my list.ejs file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>To do List</title>
</head>
<body>
<h1><%= kindOfDay %></h1>
</body>

Change outer ul background color when inner li has a class=”selected”

i have some menus with unordered list (ul)

<ul class="myul">
<li>Button1</li>
<li>Button2</li>
<li class="selected">Button3</li>
<li>Button4</li></ul>

<ul class="myul">
<li>Button5</li>
<li>Button6</li>
<li>Button7</li>
<li>Button8</li></ul>
and so on...

how i can change with jQuery the background color of outer “ul” when the inner “li” has class=”selected”?

thanks in advance.

Can’t call function within keyDown or keyPress event handlers

Can’t call function within keyDown or keyPress event handlers.

 var buttonColors = ["red", "blue", "green", "yellow"];
var gamePattern = [];

$(document).on("keydown",  nextSequence);

function nextSequence() {
   var randomNum = Math.floor(Math.random() * 4);
   var randomChosenColor = buttonColors[randomNum];
   return gamePattern.push(randomChosenColor);
}

How to Optimize Subquery in Objection JS?

I want to optimise my subquery. From the mysql doc i found.

> SELECT * FROM t1 WHERE t1.column1 IN   (SELECT column1 FROM t2 ORDER
> BY column1); SELECT * FROM t1 WHERE t1.column1 IN   (SELECT DISTINCT
> column1 FROM t2); SELECT * FROM t1 WHERE EXISTS   (SELECT * FROM t2
> LIMIT 1);

I was able to achieve this format using this objection js code.

Person.query()
  .from(
    Person.query()
      .select(
        'persons.name as persons_name',
        'persons.disclaimer as persons_disclaimer',
        'persons.id as persons_id'
      )
      .as('optimised')
      .limit(40)
  )
  .select('optimised.*')
  .select((qb) => {
    qb.select(raw(`sum(act.count)`))
      .from('activity as act')
      .where('act.p_id', '=', 'optimised.persons_id')
      .as('actCountSum');
  })
  .select((qb) => {
    qb.select(raw(`count(*)`))
      .from('activity as act')
      .where('act.p_id', '=', 'optimised.persons_id')
      .as('actCount');
  })
  .debug();

But the problem is i am getting null and 0 respectively because on where clause its passing optimised.persons_id as a string.

Any solution?

Click Instantly Triggers Event Listener That Is Created By The Click

I have a button with an event listener. When somebody clicks it, all content on my webpage gets replaced with something else, and a new event listener is put on the whole body of the page. However, clicking the button instantly triggers the new event listener that is only created after clicking it. Of course clicking the button also means that you clicked the body, but the new event listener is only created through the click, so I thought it wouldn’t instantly trigger. I don’t understand why that’s happening or how to prevent it. I hope my question isn’t too stupid. I’m pretty new to this whole thing and trying to teach myself the basics.

Edited to make my point clearer.

Is there a way to send 2 requests with a delay inbetween them without the user actively staying on the webpage

I’ll explain the question a bit clearer here.

So I have a button that sends a request through php when pressed. This request grants the user access to a Demo version of my service indefinitely. Is there a way to send a separate request 60 minutes later which is intended to expire their demo.

Could I simply create a php function that has a delay? Or would the user have to stay on the webpage in order for it to complete the function. Or is there another way to complete this that I’m not thinking of.

Thanks
-Andrew.

terms of service stripe connect

I’ve created a function to create a stripe custom company account for my users, and everything is working great, but when I try and update the terms of service data in node.js, it comes up with no errors, but when I go to the Stripe dashboard it says the account still requires a terms of service acceptance. What should I do?

Here is the function that creates the account:


export const createStripeMerchant = async (connectId: any, line1: any, line2: any, city: any, country: any, postCode: any, 
    day: any, month: any, year: any, uid: any, email: any, firstName: any, lastName: any, phoneNumber: any ) => {
    
    const account = await stripe.accounts.createPerson(
        connectId,
        {
        address: {
            line1: line1,
            line2: line2,
            city: city,
            country: country,
            postal_code: postCode,
        },
        dob: {
            day: day,
            month: month,
            year: year,
        },
        first_name: firstName,
        last_name: lastName,
        email: email,
        relationship: {
            executive: true,
            director: true,
            representative: true,
            title: 'Director',
        },
        phone: phoneNumber,
        metadata: { firebaseUID: uid },
    });

    await updateMerchantId(uid, { personAccountId: account.id });
    
    return account;
}

Here is the function that adds on the terms of service acceptance:

export const updateStripeConnect = async (connectId: any, uid: any, date: any, ip: any, userName: any) => {

    const account = await stripe.accounts.update(
        connectId,
        {
            tos_acceptance: {
                date: date, 
                ip: ip,
                service_agreement: 'full',
                user_agent: userName,
            },
        }
    );
    return account;
}

I’m calling it like this:

                            createStripePerson({
                                connectId: connectId,
                                line1: address1.val(),
                                line2: address2.val(),
                                city: cityTown.val(),
                                country: 'GB',
                                postCode: postCode.val(),
                                day: $("#dateOB").val().substring(8,10),
                                month: $("#dateOB").val().substring(5, 7),
                                year: $("#dateOB").val().substring(0, 4),
                                uid: uid,
                                email: email.val(),
                                firstName: firstName.val(),
                                lastName: lastName.val(),
                                phoneNumber: phoneInput.getNumber(),
                            }).then((result) => {
                                /** @type {any} */
                                const data = result.data;
                                const textData = data.text;
                                console.log("Result data: " + data);
                                console.log("Text data: " + textData);
            
            
                                updateStripeConnect({
                                    connectId: connectId,
                                    uid: uid,
                                    date: unixTimestamp,
                                    ip: ip,
                                    userName: firstName.val() + " " + lastName.val(),
                                }).then((result) => {
                                    /** @type {any} */
                                    const data = result.data;
                                    const textData = data.text;
                                    console.log("Result data: " + data);
                                    console.log("Text data: " + textData);
                                }).catch((error) => {
                                    console.log("Error message: " + error.message);
                                    console.log("Error details: " + error.details);
                                });
                                
            
                            }).catch((error) => {
                                console.log("Error message: " + error.message);
                                console.log("Error details: " + error.details);
                            });

So, as I said, it all goes through, but the terms of service does not get fulfilled / is still required in Stripe’s dashboard:

Stripe Dashboard Image

How to get an element value that is not showing in html code with Cypress?

this is the code of my element

<input type="text" class="nameOfClass" id="someid" name="somename" maxlength="255" placeholder="justholder" ng-model="model" tooltip-placement="top" tooltip-trigger="mouseenter" tooltip-animation="false" style="">

as you can see there is no attribute value, but I can clearly see that there is text in that text field in web app I am trying to automate.

So my problem is, that I don’t know how to get value of the text field.
I’ve tried google chrome inspector to find where is the value but without any luck. Somewhere I read, that caching can causing this problem, but in the network console I can see the values in request response.

Thanks

How to hold shift and use arrow keys in Cypress

I have an issue when using the Cypress type() command in the way I want.

My objective

I want to be able to select and delete text in a textfield. I want this done via holding the shift key, pressing the right arrow key multiple times and then pressing the delete key.

My attempt

//hold shift
cy.type('{shift}');
//navigate to end of 10 letter word
cy.type('{rightarrow}'.repeat(10));
//press delete
cy.type('{del}');

Add counter jquery

I have problem because I don’t know how to change code to add counter in name input. So when I will click #add_input new input will have name name[0], name[1] etc.

  $("#add_input").click(function () {
var html = '';
html += '<div class="row">';
html += '<input type="checkbox" name="name[0]">';
html += '</div></div>';
};

How to have moment(time).format() return in the same timezone

I’m trying to use .format() to convert the inputted time into ‘ddd, MMM DD, hh:mma’ format, but it returns it in the wrong timezone (America_NewYork)

const someday = moment('2023-01-27T12:21:08.088Z').format('ddd, MMM DD, hh:mma');

const out = document.getElementById('output');
const someday = moment('2023-01-27T12:21:08.088Z').format('ddd, MMM DD, hh:mma');
out.innerText = someday;
<script src="https://momentjs.com/downloads/moment.js"></script>
<p>Expected outcome: Fri, Jan 27, 09:21am </p>
<p>Actual outcome: <span id="output"></span></p>

Uncaught TypeError: Cannot read properties of undefined (reading ‘domElement’)

I’m new with three.js and I don’t know what’s the probleme is

    <script type="node_modules" src="./node_modules/three/examples/jsm/loaders/GLTFLoader.js"></script>
    <script type="node_modules" src="./node_modules/three/examples/jsm/controls/OrbitControls.js"></script>
    <script>
      let scene, camera, renderer;

      function init() {
        scene = new THREE.Scene();
        scene.background = new THREE.Color(0xdddddd);
        camera = new THREE.PerspectiveCamera(40,window.innerWidth/window.innerHeight,1,5000);
        camera.rotation.y = 45/180*Math.PI;
        camera.position.x = 800;
        camera.position.y = 100;
        camera.position.z = 1000;

        controls = new THREE.OrbitControls(camera, renderer.domElement);
        controls.addEventListener('change', renderer);

        hlight = new THREE.AmbientLight (0x404040,100);
        scene.add(hlight);
        directionalLight = new THREE.DirectionalLight(0xffffff,100);
        directionalLight.position.set(0,1,0);
        directionalLight.castShadow = true;
        scene.add(directionalLight);
        light = new THREE.PointLight(0xc4c4c4,10);
        light.position.set(0,300,500);
        scene.add(light);
        renderer = new THREE.WebGLRenderer({antialias:true});
        renderer.setSize(window.innerWidth,window.innerHeight);
        document.body.appendChild(renderer.domElement);

        let loader = new THREE.GLTFLoader();
        loader.load('./test_3d/scene.gltf', function(gltf){
          car = gltf.scene.children[0];
          car.scale.set(0.5,0.5,0.5);
          scene.add(gltf.scene);
          animate();
        });
      }


      function animate() {
        renderer.render(scene,camera);
        requestAnimationFrame(animate);
      }
      init();

and it return me this error:

Uncaught TypeError: Cannot read properties of undefined (reading ‘domElement’)
at init ((index):25:61)

which refers to this part of the code:

controls = new THREE.OrbitControls(camera, renderer.domElement);

React: Uncaught (in promise) DOMException: Failed to execute ‘open’ on ‘XMLHttpRequest’: Invalid URL

I am really struggling with this one as I am responsible for building this frontend but I am not the primary programmer for it so I am not sure what things I may need to check in the source code.

I looked up this error a bit and generally it seems to be an issue with the URL itself. However I do not see any issues with the URL in the console and when I navigate to the URL it complains about it loads the js chunks.

I’ve checked a number of config files on my system and have still not cracked the code yet. Any ideas?

Uncaught (in promise) DOMException: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL
    at https://my-url.internal.com/static/js/2.cbe29da6.chunk.js:2:1943240
    at new Promise (<anonymous>)
    at e.exports (https://my-url.internal.com/static/js/2.cbe29da6.chunk.js:2:1942697)
    at e.exports (https://my-url.internal.com/static/js/2.cbe29da6.chunk.js:2:4236696)
    at c.request (https://my-url.internal.com/static/js/2.cbe29da6.chunk.js:2:4235336)
    at c.r.forEach.c.<computed> [as get] (https://my-url.internal.com/static/js/2.cbe29da6.chunk.js:2:4235643)
    at Function.get (https://my-url.internal.com/static/js/2.cbe29da6.chunk.js:2:1941516)
    at https://my-url.internal.com/static/js/main.19c54516.chunk.js:2:13281
    at c (https://my-url.internal.com/static/js/2.cbe29da6.chunk.js:2:4228418)
    at Generator._invoke (https://my-url.internal.com/static/js/2.cbe29da6.chunk.js:2:4228206)