JavaScript is everywhere, but what if you want it as a scripting language in your own app or device? Duktape might be what you need. It is open source and has just reached version 1.
If you need to add JavaScript to a project then you could take one of the big engines like SpiderMonkey or V8, but the key word here is "big". Duktape is an ECMAScript 5 conformant language, and it also has some features from E6, packaged into a small footprint C program that can be linked into C or C++ projects.
Of course "small" is a relative term and 200kB of code may still be too much for some hardware. It also needs 46kB of startup RAM, but this can be reduced to 22kB. From an IoT point of view, it can work with systems that have 256kB of Flash and 96kB of RAM. To put this in perspective this means it could run on an Arduino Due but not on an Uno.
Other advantages are:
- Built-in regular expression engine
- Built-in Unicode support
- Minimal platform dependencies
- Combined reference counting and mark-and-sweep garbage collection with finalization
- Custom features like coroutines, built-in logging framework, and built-in CommonJS-based module loading framework
- Property virtualization using a subset of ECMAScript E6 Proxy object
- Liberal license (MIT)
It also has a Duktape global object which provides custom built-ins such as print() and alert().
It is also very easy to get started with. To add it to a project you simply include it, run an initialization command and then pass it the JavaScript code you want to run:
duk_eval_string(ctx, "print('Hello world!');");
where ctx is the pointer to the Duktape engine. So you can simply provide a buffer for your user to enter code and you can let them run it.
In most cases you are going to want to add custom functions to the JavaScript environment and to do this you add C functions which can be called from the JavaScript. This is easy and requires only the use of some of the Duktape API calls to pass parameters and results and to register the C function with the engine. Once registered the C function can be called just like a native JavaScript function.
In addition to being able to use Duktape as an embeddable JavaScript engine, DukLuv is a separate project which has added libuv to the Duktape engine to produce something that works like Node.js, but with a small footprint - Node.js for embedded devices if you like.
More Information
Related Articles
Node.js Fork - Now You Have A Choice To Make
Java, ASM.js Or Native - Which Is Faster?
JSFeat - JavaScript Image Processing Library
To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin, or sign up for our weekly newsletter.
Memgraph Adds AI Graph Toolkit
11/11/2025
Memgraph has been updated with the addition of two new tools; an AI Graph Toolkit that automates the porting of data into a knowledge graph in Memgraph; and an MCP Client within Memgraph Lab.
Next.js 16 Adds Cache Components
17/11/2025
Next.js 16 has been released with This release has improvements to Turbopack, caching, and the Next.js architecture.
- C# Could Overtake Java in TIOBE Index
- Join The Protest Against The Closing Of Android
- InfluxDB 3.6 Released With AI Capabilities
- Missing The Point Of LLMs
- .NET 10, C# 14 and F# 10 Released Alongside Visual Studio 2026
- Vibe Coding Is Collins Word of the Year 2025
- Cursor 2 Enables Multi-Agent Working
- TestSprite 2.0 Sees User Growth
- AI Improves Devs Skills, Enhances Their Roles
- Windows XP Crocs Now On Sale
- XAML.io 0.5 Adds Multi-File Project Editing
- Linkerd Adds MCP Support
- Apache Grails 7.0 Released
Comments
or email your comment to: comments@i-programmer.info