Building your own SDK (Software Development Kit) may sound complicated, but trust me—it’s actually simple. In this guide, we’ll walk through step by step how to:
- Build a small SDK.
- Test it in another project.
- Check which packages are installed.
And yes, we’ll keep it beginner-friendly with visuals. 🚀
🏗️ 1. Create the Project Structure
First, make a new folder called my-sdk
.
Inside it, create two files:
my-sdk/
├── package.json
└── my-sdk.js
File 1: package.json
{
"name": "my-sdk",
"version": "1.0.0",
"main": "my-sdk.js"
}
File 2: my-sdk.js
function sayHello() {
return _internalHello();
}
function _internalHello() {
return "Hello, World!";
}
module.exports = { sayHello };
👉 package.json
tells Node.js about your SDK (name, version, entry point).
👉 my-sdk.js
is the logic—here, it just returns “Hello, World!”.
🔗 2. Install the SDK Locally
Open a terminal inside the my-sdk
folder and run:
npm link
This command makes your SDK available globally on your computer.
Think of it like: “Hey npm, please remember this package everywhere.”
🧪 3. Create a Test Project
Now, let’s test your SDK.
Create a different folder (e.g., test-project
) and add a file called test.js
:
test-project/
└── test.js
File: test.js
const { sayHello } = require('my-sdk'); // Import your SDK
const message = sayHello();
console.log(message);
▶️ 4. Link and Run the Test
Inside the test-project
folder, run:
# Link your local SDK here
npm link my-sdk
# Run the test
node test.js
✅ You should see:
Hello, World!
🎉 Congrats! You just created and tested your very own SDK locally.
📦 5. How to See Installed Packages
Perfect question! After creating and testing your SDK, you might wonder:
“Which packages are installed right now?”
There are two main ways:
1. See ALL Packages Installed on Your Machine (Global)
Run this in any terminal:
npm list -g --depth=0
-
-g
= global packages (available everywhere). -
--depth=0
= shows only top-level packages (not their dependencies).
2. See Packages for a Specific Project (Local)
Go to your project folder (the one with package.json
) and run:
npm list --depth=0
Example output:
my-test-project@1.0.0 /path/to/project
├── my-sdk@1.0.0
└── express@4.18.2
👉 This tells you your project depends on my-sdk and express.
🖼️ Visual Flow
Here’s the big picture:
[ my-sdk ] --npm link--> [ global npm space ] --npm link my-sdk--> [ test-project ]
So the flow is:
- Build your SDK (
my-sdk
). - Link it globally (
npm link
). - Connect it to your test project (
npm link my-sdk
). - Run your test file (
node test.js
).
💡 Why This is Useful
- You can develop faster without publishing to npm every time.
- Any change in
my-sdk.js
reflects immediately in your test project. - You can easily check installed packages (global or local).
That’s it! You now know how to build, test, and inspect SDKs locally like a pro. 🚀
Top comments (0)