Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

254
Vistas
How to fix undefined error handling node.js
const fs = require('fs');
const fileName = './prices.json';
const file = require(fileName);
const price = require('./prices.json');
const fileName = './prices.json';


   if(tmd = message.match(/^!change max (\D+)/)) {
      if(steamID == config.ownerID){
        var kak = tmd[1];
        var sellu = 0;
        sellp = parseInt(message.replace("!change max "+kak,''));
        selli = message.replace("!change max ",'') 
        selli = selli.replace(" "+sellp,'') 
          if (file[selli].max !== undefined){
          file[selli].max = sellp;
          fs.writeFile(fileName, JSON.stringify(file), function writeJSON(err) {
            if (err) return console.log(err);
            client.chatMessage(steamID,"Succesfully changed max of " + selli)
          });
        }else{
        client.chatMessage(steamID,"There was an problem in changing, you might put wrongly name remember about capital letters or\n just do !list and ctrl+c ctrl+v")
        }
    }
  }

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'max' of undefined

for some reason does not wanna skip the error when its undefiend

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to check if file[selli] is not undefined first. otherwise u will get an Error inside your if condition.

Replace

if (file[selli].max !== undefined){

For

if (typeof file[selli] !== 'undefined' && typeof file[selli].max !== 'undefined' ) {
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda