node-gyp -- Always on Top

This blog post is about using node-gyp. node-gyp is a build tool that lets Node.js compile and install native add-ons written in C or C++. It bridges the gap between JavaScript and lower‑level system code so Node packages can use fast, native functionality.

Always on Top

In this example we will create a tool to be able to keep a window on top. Its windows only at the moment but will be extended to linux.

Environment

we'll set the following up in the course of this blog

Directory Structure

The project will be using the following directory structure

Source Code

Will be using the following source code

warning ! node-gyp is very picky about this file no whitespace at start or end of file
Required Windows SDK Components

download and run
Visual Studio Build Tools
from the installer you will need

C++ x64/x86 build tools
Go to the Workloads tab, select :
Desktop development with C++

from the tick boxes on the right, make sure to include :

MSVC v14x C++ Build Tools - ( v143 or equivalent )
This gives you:


Windows 10/11 SDK (any version)
This gives you:


That’s it.

node-gyp
npm : node-gyp

node-gyp is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js.
It contains a vendored copy of the gyp-next project that was previously used by the Chromium team and extended to support the development of Node.js native addons.

npm install -g node-gyp

node-addon-api
npm : node-addon-api

node-addon-api is not a library in the usual sense.
It’s not a DLL, not a binary, not something you “run”.
It’s a header‑only C++ wrapper around Node’s native C API (N‑API).
Meaning:

Inside node-addon-api, you’ll find:

The node-addon-api compiles these headers into your .node binary.
It needs to be installed locally in the project directory, so you will need a node_modules directory npm install node-addon-api

Build the Tool

from the project root directory
node-gyp configure --verbose node-gyp build --verbose

no errors? the node-gyp build command essentially generates a .node file
The build produces a .node file — this is a compiled native addon that Node.js can load directly. build/releases/always-on-top.node run the tool node always-on-top.js

Minimal Configuration

In the main project file, the always-on-top.js was setup to run in the build environment when we move to the minimum environment we :

node always-on-top.js
Limitations and Further Work

Simply making the current window on top has its limitations, this blog post is to demonstrate the use of node-gyp, but can easily be extended, by for instance hooking into ctrl+f1 keypress and then determine which window has focus and make it on top, find out if the window is on top, or simply ctrl+f2 make it not on top.
keep checking back.