Error , I don’t know why this doesn’t work

<!DOCTYPE html>
<html lang=”en”>

<meta charset=”utf-8″>

<pre>Cannot DELETE /api/pets/delete-pet/638d04a85116531943a6185a</pre>

  exports.deletePet = (req, res) => {

     .then((pet) => {
       if (!pet) {
             status: ' not found'
       } else {
             status: "succes"
     .catch((err) => {
       res.status(500).send('Error: ' + err);


what i expect :

{ status: “succes” }

Implement a class to generate HTML

This is what I want to do

HTMLConstruct.span('foo'); // -> <span>foo</span>
HTMLConstruct.div.span('bar'); // -> <div><span>bar</span></div>

); // -> <div><p><span>bar</span><span>baz</span></p></div>

I made this but it`s not work as it should. I have no idea how to implement it

class TestClass {
  private str: string
  constructor(str?: string) {
    this.str = str || ''
  div(str: string): TestClass {
    str = `<div>${str}</div>`
    return new TestClass(str)

Array.filter is not a function

Hi, I have a problem with filtering employee list.
I still get the error as in the screenshot. Maybe someone have a suggestion how to fix that?

  1. service
  2. model
  3. component
  4. html
  5. error
import { ChangeDetectionStrategy, Component, ViewEncapsulation } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { BehaviorSubject, Observable, combineLatest, of } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { EmployeeModel } from '../../models/employee.model';
import { EmployeeService } from '../../services/employee.service';

interface Age {
  min: number,
  max: number

  selector: 'app-filtered-employee-list',
  templateUrl: './filtered-employee-list.component.html',
  encapsulation: ViewEncapsulation.None,
  changeDetection: ChangeDetectionStrategy.OnPush
export class FilteredEmployeeListComponent {

  private _rangeSubject: BehaviorSubject<Age> = new BehaviorSubject<Age>({ min: 0, max: 100 });
  age$: Observable<Age[]> = of([{ min: 0, max: 20 }, { min: 21, max: 30 }, { min: 31, max: 40 }, { min: 41, max: 50 }, { min: 51, max: 100 }]);
  public range$: Observable<Age> = this._rangeSubject.asObservable();

  readonly employees$: Observable<EmployeeModel[]> = combineLatest([
    map(([employees, age]: [EmployeeModel[], Age]) => {
      return employees.filter(employee => employee.age > age.min && employee.age < age.max);

  constructor(private _employeeService: EmployeeService, private _activatedRoute: ActivatedRoute) {

  getAge(min: number, max: number) {{ max: max, min: min });

How to get JS array value from nth value of form dropdown?

I have the following dropdown option in a form:

<select id="candidates">
    <option value="select">Pick one</option>
    <option value="Candidate 1">Candidate 1</option>
    <option value="Candidate 2">Candidate 2</option>
    <option value="Candidate 3">Candidate 3</option>

And I also have the following array defined:

const selectedcandidate = ["/image1.png", "/image2.png", "/image3.png"];

I’m trying to declare a variable that will contain the image file of the corresponding candidate that was selected from the dropdown:

finalselectedcandidate = selectedcandidate[candidates[n]];

However, the code above doesn’t work. What would be the best way to accomplish this?

how do I link my src/app.js file to babel

src/app.js file keeps showing it doesn’t exist in git bash

I tried adding quotations
babel src/app.js –out-file=public/scripts/app.js –presets=”env,react”
instead of this

babel src/app.js –out-file=public/scripts/app.js –presets=env,react but it still did not work

No console log in chrome, just ReferenceError with axios

Hello im a newbie when it comes to js, but I built this web scrapper ( ‘Index.js’) and was trying to pass it into my (‘index.html’) file and view it thew the inspection window on my browser and can’t get it to work. In console im just seeing

Uncaught ReferenceError: require is not defined
    at index.js:6:15

index.js6:15 —- const axios = require(‘axios’)

-------------index.html file (im trying to load in chrome):

The scraper works when i run it through npm node as you can see in the terminal in VScode ( Picture attached). I would expect to see the list logged in the console on chrome, but all I get is the error. Sorry if im overlooking something simple my apologies.

`<!DOCTYPE html>
<html lang="en">
    <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>BFL Extension</title>
        <li id="bfl"></li>
<script src="index.js"></script>`

————index.js file with web scraper:

`const port = 3000

const axios = require('axios');
const cheerio = require('cheerio');
const express = require('express');

const app = express();

const url = ''

axios.get(url, { headers: { Accept: 'application/json', 'Accept-Encoding': 'identity' }, params: { trophies: true } })
    .then(response => {
        const html =
        const $ = cheerio.load(html)
        const list = []
        $('.level-1', html).each(function(){
            const number = $(this).text().replace(/D/g,'');
            const name = $(this).text().replace(/[0-9]/g, '')
            const link = $(this).find('a').attr('href')
    }).catch(error => console.log(error))

app.listen(port, () => console.log(`server running on PORT ${port}`) );`

Test for Button click to call a mocked function fails

Attempting to teach myself testing for React with react-testing library and jest as this is what my work uses. For the life of me I can not figure out why the mock function testClick is not being called. I have researched articles and watched videos however most seem outdated as it appears the testing world changes how code should be written super fast. Anyone have thoughts? Here’s the code :

Products.js component :

import React, { useState } from 'react';
import { fetchProducts } from '../service';

const Products = () => {
  const [product, setProduct] = useState('');

  const handleSubmit = (event) => {

  const hasBeenClicked = () => {

  return (
    <form onSubmit={handleSubmit}>
          onChange={(e) => setProduct(}

export default Products;

Products.test.js :

import React from 'react';
import { render, screen, cleanup, fireEvent } from '@testing-library/react';
import Products from './Products';

test('Button click triggers click event', () => {
  const testClick = jest.fn();
  const { getByTestId } = render(<Products click={testClick} />);
  const button = getByTestId('button');;


Results in :

 PASS  src/App.test.js
 FAIL  src/components/Products.test.js
  ● Console


      at apply (src/components/Products.js:13:13)

  ● Button clicks triggers click event


    Expected number of calls: >= 1
    Received number of calls:    0

      11 |;
      12 |
    > 13 |   expect(testClick).toBeCalled();
         |                     ^
      14 | });
      15 |

      at Object.<anonymous> (src/components/Products.test.js:13:21)

Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        3.18 s, estimated 4 s

How can I get gmail label names into a list? In google sheets or otherwise

In google app script

I’m trying to take the gmail labels and print them in a clean list or line where I can suffix every line to easily make filters in bulk. Like this: labelname1, labelname2, labelname3, etc.
Any help is greatly appreciated

This is as close as ive gotten. Im mainly trying to get it to print to google sheets. But anywhere works, as long as its in correct format.

// Logs all of the names of your labels
function retrieveLabelNames() {
var labels = GmailApp.getUserLabels();
for (var i = 0; i < labels.length; i++) {

Redis javascript ZADD is not a function?

I am getting TypeError: client.zadd is not a function
, zadd is valid redis function.

CLI: zadd ‘zkey222’ 12 ‘123’ , works fine.

import { createClient } from 'redis';

const client = createClient();

client.on('error', (err) => console.log('Redis Client Error', err));

await client.connect();
await client.set('key', 'value');
await client.zadd('zkey222', 12, '123');

const value = await client.get('key');

await client.disconnect();

How to delay ajax using jquery

I need to access an API but I dont want to shoot with 100 requests at the same time so I want to make 1 request per second so I write:

$.each(added_collections, function(index, collection) {
      $.each(collection, function(index1, page) {
        $.each(page, function(index2, product) {
               setTimeout(function() {
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            type: "POST",
            url: '/get_data',
            dataType: "json",
            data: meta_data,
            success: function(data) {
           error: function(data){

          }, 1000);

but this code do not make 1second between requests

enter image description here

How I can make 1 ajax call per second

How findOneAndUpdate Method works, getting null as a result

What i am trying to create, find a comment based on commentId also finding that particular comment which should not be postedBy currently loggedin user
I am trying to create commentVote functionality, loggedIn user cant vote his comment or post.
getting null as a result

my voteComment Controller Method –

exports.voteComment = (req, res) => {
  const { commentId } = req.params;
  if (!ObjectId.isValid(commentId)) {
    return res.status(400).send({
      error: "Comment ID not valid",
  console.log(typeof req.auth._id);
    { commentId, "comment.postedBy": { $ne: req.auth._id } },
    { $push: { votes: req.auth._id } },
    { new: true }
    // { omitUndefined: true }
    // { returnNewDocument: true }
  ).exec((err, result) => {
    if (err) {
      return res.status(400).json({
        error: "Could not vote on that comment",
    // if (result.nModified) {
    //   console.log("test");
    // }

My Comment Model-

const mongoose = require("mongoose");
const { ObjectId } = mongoose.Schema;

const commentSchema = new mongoose.Schema(
    content: {
      type: String,
      required: true,
      trim: true,
      max: 200,
    postedBy: {
      type: ObjectId,
      ref: "User",
      required: true,
    feature: {
      type: ObjectId,
      ref: "Feature",
      required: true,

    votes: [{ type: ObjectId, ref: "User" }],
    replies: [
        content: {
          type: String,
          required: true,
          trim: true,
          max: 200,
        postedBy: {
          type: ObjectId,
          ref: "User",
        created: {
          type: Date,
        votes: [
            postedBy: {
              type: ObjectId,
              ref: "User",
            created: {
              type: Date,

  { timestamps: true }

module.exports = mongoose.model("Comment", commentSchema);

I also want to create error handling so that if Comment isn’t updated so i can modify it by checking if(comment.nModified)
but i dont know how to use .nModified and .ok on response from mongoose

When iPhone scans a QR with built in camera capabilities it opens it is SafariI. Is it possible to detect this case with JavaScript?

The problem is that in this case there is no option to install the page in Home Screen. I would like detect the situation and issue a message to guide the user on how to do it: select navigator button to open the page in Safari, which then will have the option to install in Home Screen.

I don’t know if there is an user agent string specific to case when safari is opened by qr reader.