Node Termux Api Save Abandoned

A Node.JS wrapper module for Termux-API

Project README

Termux-API Wrapper for Node.JS

This Repository is Unmaintained and Archived (Read-Only)

Unfortunately, due to my work, i could not maintain this repository updated at this moment.

This project aims to create a simple interface to invoke Termux-API commands directly from Node.JS applications. To use it you need to have Termux and Termux-API installed on your Android, and Node.JS installed on the Termux environment.

What is Termux?

From Termux Website: "Termux is a terminal emulator and Linux environment bringing powerful terminal access to Android."

With Termux you can run a small linux environment on your Android device, that means that you can run a small command-line utilities or a full-featured webserver directly from your Android phone.

Install Termux from Google Play


Termux-API is a companion app to Termux, it creates an interface from Termux to your device features, with Termux-API you can take photos from your phone camera, get location from GPS, read or send SMS, and a lot of other features. Everything directly from the emulated Linux terminal.

Install Termux-API from Google Play

Node.JS on Termux

Termux brings the possibily of running Node.JS on your Android device by simply installing it with APT (without rooting):

apt update
apt install nodejs


Install the package on yout NPM project by:

npm install --save termux-api

Import the default object on JavaScript:

var api = require('termux-api').default;

Or with TypeScript:

import default as api from 'termux-api';

Now you have a instance of the class TermuxApi as the api variable. To invoke API commands you must build it using the method createCommand().

The method createCommand() returns an instance of the ApiCommandFactory where you find one method for each API command you could invoke on Termux-API app. For example, to show a small popup, or toast for those familiarized with Android UI you can use:

    .setText('Can you see me?')
  • line 1: api.createCommand() returns an instance of ApiCommandFactory class.
  • line 2: ApiCommandFactory.toast() returns an instance of ToastBuilder class.
  • line 3: ToastBuilder.setText() sets the text to be displayed and returns the ToastBuilder himself.
  • line 4: ToastBuilder.shortDuration() configures the toast to be displayed for a short while and returns himself (ToastBuilder).
  • line 5: builds and return a ApiCommand instance.
  • line 6: The command is run.

The process for calling other commands are very similar, you only need to change the command (line 2) and the options (lines 3 and 4). For example, to vibrate the phone for 1 second (1000 ms):


You can see all commands available on ApiCommandFactory source-code. And options for each command are availabe on the correspondent class in the builders folder.

Returning data from the API

Some API commands return data as String or JSON. To gather that data you could use the instance of ApiResult class returned by the method run() by invoking the methods getOutputObject() or getOutputString().

Notice that those 2 methods executes asynchronously returning ES6 Promises that resolves to an Object ou a String, respectively.

For example to get a location update from GPS and show the returned object on console:

let result = api.createCommand()

    .then(function(location) {
        console.log('Last known location: ', location);

Open Source Agenda is not affiliated with "Node Termux Api" Project. README Source: edupsousa/node-termux-api
Open Issues
Last Commit
5 years ago

Open Source Agenda Badge

Open Source Agenda Rating