#node

Found 23 articles tagged with #node

How to create a sleep or delay in Node.js

A sleep or delay function is a programming feature that allows you to pause the execution of a program or a specific part of a program for a specified amount of time.

How to delete a file in Node.js

You can use the fs module, which provides methods for working with files and directories: Using fs.unlink() to delete asynchronously, or fs.unlinkSync() to delete synchronously.

Sep 14, 2023#node#javascript

How to get current folder in Node.js

Current folder refers to 2 possible locations: current folder in project using __dirname variable, and current working directory using process.cwd or dot-slash notation.

Jul 20, 2023#node#how-to

How to promisify a function in Node.js

Promisifying is converting a callback-based function into a function that returns a promise, which allows you to use promise chaining or convenient async/await syntax.

Jun 30, 2023#node#how-to

Top 6 End-to-End Testing Frameworks

End-to-end testing is essential for web development, as it can detect bugs and errors that may not be visible in unit or integration testing; Playwright, Cypress, Puppeteer, Selenium.

How to turn an image into a data URI string in Node.js

You can use data URI strings to include small files or binary data in your web pages without having to make separate HTTP requests for them.

May 13, 2023#node#how-to

How to check if file exists in Node.js

Whether you need to verify if a file exists before performing an operation or simply want to handle different scenarios based on file availability.

May 12, 2023#node#how-to

Sync, callback, and promise based APIs in Node.js

"async/await" syntax in newer versions of Node.js simplifies working with promises, making asynchronous code resemble synchronous code in terms of readability and flow control.

May 11, 2023#node#comparison

How to fix error "__dirname is not defined in ES module scope" in Node.js

If you have enabled ES modules in Node.js or using ES modules through a module bundler like Webpack, you'll no longer have access to many variables compared to CommonJS.

How to fix error "cannot use import statement outside a module" in Node.js

This error means that you are trying to use the import statement in a file that is treated as a CommonJS module by Node.js. There are a few ways to fix this error, depending on your preferences and project setup.