What is module in Node.js?

Deep dive into creating and exporting functions and objects from modules

Module in Node.js? In Node.js each file is treated as separate module. For example, consider below code // ES5 syntax - file math.js module.exports.add = () => a + b What is module.exports in above code? Each module is wrapped in function by Node.js before execution as shown below ;(function(exports, require, module, __filename, __dirname) { // Module code actually lives in here }) During execution our code will look like the following: [Read More]
nodejs 

What is libuv?

A quick intro to libuv - Node internals

libuv is C++ open source library that gives Node.js access to OS internals, Networking and Concurrency. It was primarily developed for use by Node.js, but it’s also used by Luvit, Julia, pyuv, and others. What is libuv? libuv is built on top of epoll/kequeue/event ports/etc on Unix and IOCP on Windows systems providing a consistent API on top of them. Features of libuv Full-featured event loop backed by epoll, kqueue, IOCP, event ports. [Read More]
nodejs 

How to track folder or file changes in Node.js?

Watch folder(s) when its contents are changed

Problem How to observe/watch the folders OR files that gets changed using Node.js Solution Node.js comes with builtin method fs.watch() method that will emit ‘change’ event whenver specific directory or file is modified Example fs.watch( './folder/or/file/path/to/watch', { encoding: 'buffer' }, (eventType, filename) => { if (filename) { console.log(filename) // Prints: <Buffer ...> } } ) Save above code in watch.js file and run the program node watch.js. Make sure you change folder or file name. [Read More]
nodejs 

What is Node.js?

Simplified and quick intro to Node.js

Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. Its nonblocking event-driven architecture makes it suitable for intensive I/O applications. Before we look at Node.js we should get familiar with V8. What is V8? V8 is JavaScript Engine that uses the same JavaScript interpreter as Google Chrome. V8 compiles javascript to native machine code and executes it. It also, optimise the code to run it faster. Similar to V8 we have other JavaScript engines mentioned below for popular web browsers [Read More]
nodejs