Browsed by
Tag: JavaScript

The difference between “fulfill” and “resolve” a Promise

The difference between “fulfill” and “resolve” a Promise

When we are working with Promises in Javascript, there are two terms commonly confused: fulfill and resolve. According to the dictionary: Fulfill: Bring to completion or reality; achieve or realize (something desired, promised, or predicted). Resolve: Settle or find a solution to (a problem, dispute, or contentious matter). That’s everything we need to solve all the mess around these terms that we tend to use indistinctly. Let’s take the next code snippet as an example: According to the definition of Promise, the method resolve can receive either…

Read More Read More

Turn HTML into PDF with Node.js

Turn HTML into PDF with Node.js

As the title says, today’s post is about how to generate a PDF file based on HTML content, all in Node.js. To generate PDF files for reports or downloadable content is very common in a certain type of applications where those documents play the role of reports or receipts for a transaction. Unfortunately, while some documents are basically plain text, others require a more complex structure to display all that data. If that’s the case, you can get help with…

Read More Read More

How to replace content in static files with Node.js

How to replace content in static files with Node.js

Sometimes we have HTML files with content that depends on the environment or a variable in order to render specific content and send it to the browser. A natural way to handle this type of use cases is by using a server-side rendering library like handlebars or pug. Unfortunately, to include these libraries is not always possible or we don’t want to set up the project to support them. If that’s the case (as it was for us) you’ll find…

Read More Read More

Add documentation to your API in Node.js

Add documentation to your API in Node.js

These days, document your API is a great idea if you: Work with separated teams for backend and frontend development, Have a public API, Are going to hand off the project and others need to work on it without your help In case you are working with Node.js, we like to use the solution offered by apidoc https://www.npmjs.com/package/apidoc The documentation generated by this package is not automatic so that you’ll have to describe your API resources. This may look like a…

Read More Read More

Beautify your code… with code!

Beautify your code… with code!

Automatization is an important area of software development. As developers, we should always look for ways to be more productive and do more with less. These days, here at Regos, we are investing some time in code generation and tasks automatization. Thanks to those tasks we found this nice npm package: https://www.npmjs.com/package/js-beautify The basic idea is to generate the code however you want and just format the generated files with this package. Here is an example of the basic usage. To be…

Read More Read More