Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

230
Visualizações
Why nodejs use magic strings in its core modules willy-nilly?

I'm learning nodejs and having previous experience with other {strongly typed} languages I'm suffering a bit finding the reason why there is so much abuse of magic values (mainly strings) in core modules of nodejs.

Just to give an example, let's take the implementation of the http module which has classes that extends EventEmitter and relies on strings to identify events, such as the http.Server class with its 'connection', 'connect' and 'request' events identifiers.

Is there a reason for that? Isn't there any better way to achieve that (like just using an object for instance)?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Is there a reason for that?

ECMAScript does not have enumerations. To model them, one would have to use one of the available types, namely numbers, strings or objects (or symbols, though they're younger than NodeJS). Now "magic strings" are far better than "magic numbers" or "magic empty objects".

about 4 years ago · Juan Pablo Isaza Relatório

0

I am not 100 % sure, but the formal definition on the official Node website describes Node as “a JavaScript runtime built on Chrome’s V8 JavaScript engine.” and v8 was primarily built for the client side i.e web. So, if you look at the web events, you will see this pattern being used. Probably that is why i think.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda