How I migrated a JavaScript project that was using Mongoose to TypeScript

Photo by AltumCode on Unsplash

A few months ago, my team started to move a JavaScript project, only dedicated to be a data access object module for Mongo collections using Mongoose, to use TypeScript. The main reason for this “migration” was to have a well-defined interface for every property and method (static and instance) available for each model/document.

To make this process incremental we didn’t migrate every collection at once but we follow a process like:

  • Change the entry point for the module
  • Start migrating files

One main objective was never to break a defined…

Writing tests is a crucial part of software development. The more common ones are unit or integration test and these are the ones that are the most relevant for this article.

The idea behind debugging a test is to depend less on “console.log” expressions and helps to find that thing that makes our test fail. In the Javascript world, with “zero compile time” and the faster start times, we tend to write some “console.log”, run and see what…

A few days ago I was working on a task in which I had to write an endpoint to download a file from the server.

As usual, for every code we write in the team (at least for the backend side), we write the correct test cases. Until now, I had written test cases that checked the returned HTTP code, the correct Content-Type, Content-Disposition and Content-Length headers and that’s all. This time, I wanted to check that I’m downloading the correct file (check the content I’m receiving).

First, I was thinking that it would be just checking the “body” in…

Si una palabra se ha extendido en los últimos meses por todo el mundo, además de la tristemente conocida “COVID-19", es “teletrabajo” y esta, poco a poco se ha ido adueñando de portadas de periódicos y noticiarios, entradas en blogs, etc… .

Lo que debemos destacar es que para nada es algo nuevo, sólo en Estados Unidos desde 2005 hasta 2019 hubo un aumento de un 159% en esta tendencia (artículo en inglés). …

After working with Node.js for more than 5 years, I can say that its package module system is one of the keys to its large adoption in many companies. In my case, I used to take advantage of this feature.

In my team, we follow some rules to organize our code:

  1. When a code is required for several projects, we create a module with a concrete mission and a defined interface. Then, we require the module in every project that needs the functionality.
  2. When a…

A few months ago, the Linux Foundation published the expected Node.js certifications: OpenJS Node.js Application Developer and OpenJS Node.js Services Developer. Here you will find all the needed information about the certification requirements, topics, process, and prices. By now, when you get the voucher for the exam, you will get a free 2nd attempt.

The Candidate Handbook and the Tips Document are two important documents I recommend you to read carefully.

By the time I first started to look for information about the exam I didn’t find much available except these two articles which helped me to understand the process…

Hace ya unos meses, la Linux Foundation, presentó las esperadas certificaciones para Node.js: OpenJS Node.js Application Developer and OpenJS Node.js Services Developer. En estos enlaces podrás encontrar toda la información necesaria sobre los requisitos, temario, proceso para el examen y precios (hasta el 31 de Mayo de 2020, está disponible un descuento del 30%). Al menos por ahora, cuando obtienes el voucher para tu examen, obtienes también un segunda oportunidad en caso de no pasar el examen a la primera.

Dentro de la información disponible en el sitio oficial, el Candidate Handbook y el Tips Document son dos documentos importantes…

Almost every time I interview someone to work with Javascript, I use to make a question: “if I told you, hey, XXXX what is what you think I have to learn to start with Javascript and know it well (assume I already know how to program in any other language)?”

I have hear many different answers, thinks like: ES6, Promises, React,…

In the interviews I like to turn them in more a conversation than a questioning and like for other questions, I use to give mine about this one, here are the thinks I use to say:

Javascript is…

Every time I talk with people about TDD, the main topic is the difficulty of doing it well. I use to say that it’s no so easy as some people say it is, but also, is not so hard either.

From my point of view, you need to have 3 things:

1- To have a clear and well defined functionality: someone have to define the behaviour you have to code. It includes defining how it should behave when it works fine and also when it fails in any way it can.

2- To have a good level of envolved technology

In a previous post we saw the importance of the.lean() in your queries when you are using mongoose and you need to find out a big amount of data(and you don’t need any mongoose hook) to save time in your process.

Today we are going to see how to save time when you need to write that information into another mongodb collection.

Let’s see the code:

In this code we are making a find query, using lean() and a cursor to go through all the elements in our query.

We are “saving” the element in an array until we…

Ángel Cereijo

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store