Express-validator runs validation chain in unexpected way

I am using express-validator to validate user name and email while creating user, the name which has the following validation chain

body("name")
.notEmpty()
.withMessage("Name is required")
.isString()
.withMessage("Name must be string")
.isLength({ min: 3 })
.withMessage("User name must be at least 3 character long")
.isLength({ max: 30 })
.withMessage("User name must be less than 30 character")
.custom((value) => /^[a-zA-Zs]+$/.test(value))
.withMessage("Name only contain alphabetic characters")

gets validated when i call create api and i am not passing name field in the body, then according to express-validator it must goes through the whole chain and returns all the errors occur in validaion chain but, I am getting only three errors as

errors: [
{
  type: 'field',
  value: undefined,
  msg: 'Name is required',
  path: 'name',
  location: 'body'
},
{
  type: 'field',
  value: undefined,
  msg: 'Name must be string',
  path: 'name',
  location: 'body'
},
{
  type: 'field',
  value: undefined,
  msg: 'User name must be at least 3 character long',
  path: 'name',
  location: 'body'
}

]

why it is not giving me all the errors.

Strapi merge hosts

Help me to understand,
There is an admin panel on Strapi, and there is a client personal account, now everyone opens on their own host,
how can they be combined?
To /admin – open strapi,
and /client opened the client’s website on one host

I can’t really find anything in the documentation! At least a link and preferably with an example

Remove ads from embedded iframe

I embeded an iframe on a page and I blocked some features(the pop-up ads) from loading with the sandbox option. I’ve managed to remove the ads from the iframe just by using the sandbox option. Is there any other way to remove the ads like adblock does, but with code?

What I have tried:

Somehow I managed to remove the ads by using a certain combination of sandbox’s options, but it works on all browsers except Google Chrome (desktop version).
I want to know if it’s possible to remove the ads in another way.

Code example:<iframe src="https://openload.co/embed/K_KIUHM9_nI/" sandboxscrolling="no" frameborder="0" width="700" height="430" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" sandbox="allow-scripts"></iframe>

The main differences between using class-validator library vs. zod to perform request body validation

I am learning NestJS and I’ve recently discovered the two methods commonly used to perform request body validation using the libraries Class-validator and Zod.

I’ve read the NestJS documentation on Pipes. They give two examples. In Object Schema Validation section, they’re using the Zod library to build a validation pipe.

In additional it includes an alternate method for performing validation using the Class-Validator library in the section class-validator.

I would like to understand a few things about these two libraries and their ideal use cases**.**

Here are my questions:

  • What are the primary differences between using Class-validator vs Zod for performing validation inside of pipes?

  • In what situations would you need to use Class-validator over Zod and vice versa…?

  • Can both libraries be used in conjunction? If so, what are the use cases?

Any help will be appreciated. Thanks!

I really dont understand what exactly is being concatinated to arr , as res is just the recursive function but not an array

var getElementsByClassName = function(className, element = document.body) {
    var arr = [];
    if (element.classList && element.classList.contains(className)) {
        arr.push(element);
    }
    for (var i = 0; i < element.childNodes.length; i++) {
        var res = getElementsByClassName(className,      element.childNodes[i]);
        arr = arr.concat(res);
    }
    return arr;
};

At first i thought i understand and i assumed that arr is concatinating the content of arr that gets initialized with a new element in each recursive call , but then i found out that im wrong , or if im not wrong then how does that even work ? As var res is holding the recursive call but whats even its content to be concatinated with arr ? I mean im lost guys and Can we get rid of the var res and instead using arr = arr.concat(getElementsByClassName(className, element.childNodes[i]))
please someone explain the whole procces and thank you very much .

Google Access Token Error: Request had invalid authentication credentials. – Javascript

when running the default code to obtain an access token, I am getting the error:

{
  error: {
    code: 401,
    message: 'Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.',
    errors: [ [Object] ],
    status: 'UNAUTHENTICATED'
  }
}

from code (source: https://firebase.google.com/docs/auth/web/google-signin):

import { getAuth, signInWithPopup, GoogleAuthProvider } from "firebase/auth";

const auth = getAuth();
signInWithPopup(auth, provider)
  .then((result) => {
    // This gives you a Google Access Token. You can use it to access the Google API.
    const credential = GoogleAuthProvider.credentialFromResult(result);
    const token = credential.accessToken;
    // The signed-in user info.
    const user = result.user;
    // IdP data available using getAdditionalUserInfo(result)
    // ...
  }).catch((error) => {
    // Handle Errors here.
    const errorCode = error.code;
    const errorMessage = error.message;
    // The email of the user's account used.
    const email = error.customData.email;
    // The AuthCredential type that was used.
    const credential = GoogleAuthProvider.credentialFromError(error);
    // ...
  });

I believe this is telling me that what I am using now is deprecated (https://developers.google.com/identity/sign-in/web/sign-in): enter image description here

However, I have not found any workaround code to generate the access token required to use Google API services. Does anyone have a solution to this problem / managed to access Google API services despite the deprecation with Javascript?

My innerHTML is blank when i try to make it show the value in HTML side I don’t know how but let see my code (google app script)

If the question is very confuse I’m so sorry I’m very new to coding and not good at writing in english and here my problem i try to make a minigame for myself with google app script and when i clicked the Attack button it will call the Attack() function and the paragraph (ID : re) should be show a MonsterHP but it turn out to be blank

Note : I declared MonsterHP and WeaponTough outside the AttackMons() function (Ex. var MonsterHP = 200;) and other variable has it constant value i think it unnecessary to write here

HTML

HTML

Client

Client

Server

Server

I tried run the code and the paragraph change from “Result of Attack : “ to blank “ “

Javascript Objects and Array Console Logging the same output Before and After Modification [duplicate]

I was to modify an array’s data by swapping the element .Eg: [[1,2],[3,4]] => [[2,1],[4,3]].

Now Below it shows the same value which will be after modification when printing ‘data’, but diffrent or correct while printing data.coordinates which is the actual array.

Why is it happening.

        const url = `http://router.project-osrm.org/route/v1/driving/${start.lng},${start.lat};${end.lng},${end.lat}?overview=full&geometries=geojson`;
        try {
          const response = await axios.get(url);
          let data = _.cloneDeep(response.data.routes[0].geometry);
          console.log('route data before swap ', data , data.coordinates )
                  setRoute2(data)
          data.coordinates = data.coordinates.map(cords=> [cords[1],cords[0]] )
          console.log('route data after wap ', data , data.coordinates)
          setRoute(data);
        } catch (error) {
          console.error('Error fetching route:', error);
        }
      };

I tried using loadash but to no avail.
Checked and doest seem to be chrome issue, since using coordinates directly in my GeoJson Map renders both routes perfectly.

“node:internal/modules/cjs/loader:1146” error in react app installing

Getting these errors in console

node:internal/modules/cjs/loader:1146
  throw err;
  ^

Error: Cannot find module '../../package.json'
Require stack:
- C:UsersadityAppDataRoamingnpmnode_modulesnpmlibes6validate-engines.js
- C:UsersadityAppDataRoamingnpmnode_modulesnpmlibcli.js
- C:UsersadityAppDataRoamingnpmnode_modulesnpmbinnpm-cli.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
    at Module._load (node:internal/modules/cjs/loader:984:27)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (C:UsersadityAppDataRoamingnpmnode_modulesnpmlibes6validate-engines.js:8:49)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
    at Module.load (node:internal/modules/cjs/loader:1206:32)
    at Module._load (node:internal/modules/cjs/loader:1022:12)
    at Module.require (node:internal/modules/cjs/loader:1231:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\Users\adity\AppData\Roaming\npm\node_modules\npm\lib\es6\validate-engines.js',        
    'C:\Users\adity\AppData\Roaming\npm\node_modules\npm\lib\cli.js',
    'C:\Users\adity\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js'
  ]
}

Node.js v20.12.1

what should i do

Tried : deleting and reinstalling the latest node packages
also tried npm uninstall json-server
and no commands of npm is running in every case the result is same

Props not updated properly in class component

I have a class component which does not update upon props change. What I do not quite understand is that in mapStateToProps, the console.log(appSettings.appState) logs the update value.

const mapDispatchToProps = dispatch => {
  return bindActionCreators(
    {
      setFoo,
    },
    dispatch,
  );
};

const mapStateToProps = state => {
  const { appSettings } = state;
  console.log(appSettings.appState) // this logs when the appState changes
  return {
    appState: appSettings.appState,
  };
};

const EnhancedFooBar = props => {
  const database = useDatabase(DATABASE_NAME);
  return (
    <Mapp
      {...props}
      database={database}
    />
  );
};

export default connect(mapStateToProps, mapDispatchToProps)(EnhancedFooBar);

However, when I try to log appState in the render() function, the update value gets not

render() {
    console.log(this.props.appState) // this only logs on first render, but not when appState changes
    ...
}

I do not have implemented a shoouldComponentUpdate(), only a componentDidMount() and componentDidUpdate(). Note that in componentDidUpdate() this also does not console.log the update value.

how to pass an array name to the controller from an input with name that is array in html without using ajax, just pass it to controllers parameter

<div class="col-md-3 ingname">
  <input class="form-control ingredient-name" placeholder="Ingredient Name" id="ingredientName[]" name="ingredientName[]" required />
</div>
<div class="col-md-3 ingqty">
  <input class="form-control ingredient-quantity" placeholder="Quantity" type="number" min="0" id="ingredientQty[]" name="ingredientQty[]" required/>
</div>

how to pass these inputs to a controller

is this correct?

public ActionResult UploadRecipe(Recipe recipe, string ingcount, string moodid, string[] ingredientName, int[] ingredientQty, string[] ingredientUnit) {

How to get data loaded asyncronosly from load functions of SvelteKit?

I am new to Svelte and want to do something like this in my +page.js:

export async function load() {
    let prom = new Promise((res) => {
        setTimeout(() => res('myData'), 10000)
    })
    let value = await prom
    return {
        value
    }
}

And the following is my +page.svelte:

<script>
    export let data
</script>

{#if data?.value}
  <pre>data is {data.value}</pre>
{:else}
  <pre>data is Loading...</pre>
{/if}

But, I am not getting the :else part on my page at all. Instead, the entire page keeps loading for a whole 10sec and then flashes the data value directly. How can I achieve the expected?

why does my terminal freeze when i am trying to install something in the terminal through npm?

I am new to NodeJS , and while trying to download third party libraries, the terminal just freezes. If i restart the pc and run the command again, it directly starts downloading.

this is happening every time

PS D:Node_js_folderExpress_Startup>  npm install --save body-parser
[..................] / idealTree:Express_Startup: sill idealTree buildDeps



PS D:Node_js_folderExpress_Startup> npm install body-parser

up to date in 1m

16 packages are looking for funding
  run `npm fund` for details

Can anyone help identifying where is the problem occuring as restarting every time is very annoying.

Issue with Mutating State Array in React Component

Description:

I’m encountering an issue with updating a state array in a React component, specifically when dealing with 2D arrays. Despite following the recommended approach of immutably updating state using setState, I’m facing difficulties in ensuring that my state array is updated correctly.

Background:

I’m working on a React component that calculates the minimum cost path in a grid. The component maintains a state array called history, which stores the cumulative costs at each step of the calculation. The calculateMinimumCost function iterates through the grid, updating the history array with the cumulative costs for each step.

Problem:

While attempting to update the history array immutably using setState, I encountered unexpected behavior. Specifically, when attempting to update the history array with 2D arrays representing the cumulative costs, the state update does not reflect the expected changes. As a workaround, I’ve resorted to stringifying and parsing the 2D arrays before updating the state, which seems to resolve the issue, but I understand that this is not the recommended approach.

GitHub | Minimum Cost Path JS

Code Example:

// Example of problematic state update
setHistory([...history, [...minimumCostGenerator]]); // Does not update state as expected

// Workaround using stringify and parse
this.state.history.push(JSON.stringify([...newHistory])); // Works, but not recommended

Question:

I’m seeking guidance on how to properly update a state array containing 2D arrays in React without resorting to workarounds like stringification and parsing. What could be causing the issue with the state update, and how can I ensure that the state array is updated correctly while adhering to React’s best practices?

Any insights or suggestions would be greatly appreciated. Thank you!

Vercel same code showing of entry file index.js

All things working fine but only issue with entry file index.js i think, I am seeing same index.js file code in the ouput of vercel deployment and there should be like server is ready, now how to solve this issue and further more without environmental varialbes the issue is same and after inserting env file problem again same.

i have deleted and deploy again and again same problem accruing