Hey, I'm Marco and welcome to my newsletter!
As a software engineer, I created this newsletter to share my first-hand knowledge of the development world. Each topic we will explore will provide valuable insights, with the goal of inspiring and helping all of you on your journey.
In this episode, I'll show you the Node.js libraries I use in almost all of my projects. I've collected them over about four years of use, and I think it's interesting to share them with you.
👋 Introduction
Node.js libraries are powerful tools that developers use to add functionality to their applications.
They provide ready-made solutions for common programming tasks, saving time and effort in development. Libraries also promote code reusability, allowing developers to leverage existing code instead of reinventing the wheel. Additionally, using libraries can improve code quality and maintainability by following established best practices and standards maintained by the library authors. Overall, smart use of Node.js libraries can make development processes smoother and improve how applications work.
However, it's important not to overuse them. Using libraries excessively can make your code too big and slow down how it runs. It's better to use libraries wisely, concentrating on their main features and avoiding unnecessary extras. This keeps your code organized and makes sure your application runs smoothly.
📚 My Libraries
Here are the libraries I typically install for most of my projects, along with specific examples of how to use them:
axios
dotenv
jsonwebtoken
lodash
luxon
memoizee
nodemon
nodemailer
p-queue
yargs
📡 Axios
Axios is a popular library with 40M+ weekly downloads, used for making HTTP requests from both the browser and Node.js environment. It provides a simple and intuitive API for handling asynchronous HTTP requests, supports Promises for efficient request handling, and offers features like interceptors for request/response manipulation. Axios also automatically handles JSON data conversion, making it a versatile choice for web development on both the client and server sides.
I use it because it makes HTTP calls to external services easy to use, whether the content type is application/json, application/x-www-form-urlencoded or FormData.
You can install it in your project with:
yarn add axios
I'll show you an example of how I used it within a method to make an external call to ChatGPT:
const computeSummaryEndpoint = async (text, user_message) => {
const body = {
model: "gpt-3.5-turbo-0125",
messages: [
{
role: "user",
content: text
},
{
role: "user",
content: user_message
}
],
temperature: 1,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0
};
const { data } = await axios.post('https://api.openai.com/v1/chat/completions', body, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`
},
});
const summary = data.choices[0].message.content
return summary
}
NPM Package: https://www.npmjs.com/package/axios
🔑 Dotenv
Keep reading with a 7-day free trial
Subscribe to Implementing to keep reading this post and get 7 days of free access to the full post archives.