Skip to content

How to determine that current instance of Node.js is running on Termux? #56422

Answered by dax-side
irvnriir asked this question in General
Discussion options

You must be logged in to vote

You can determine if the current instance of Node.js is running on Termux by checking the PREFIX environment variable, which is unique to Termux. Here's a concise implementation:

const isTermux = () => {
const termuxEnv = process.env.PREFIX;
return termuxEnv && termuxEnv.includes('com.termux');
};

if (isTermux()) {
console.log('Running on Termux');
} else {
console.log('Not running on Termux');
}

Explanation:

  1. Why PREFIX?
    In Termux, the PREFIX environment variable is set to /data/data/com.termux/files/usr, which identifies Termux's unique environment.

  2. How It Works:
    The function checks for the existence of process.env.PREFIX and verifies if it contains the string com.termux, making it a…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@irvnriir
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by irvnriir
Comment options

You must be logged in to vote
1 reply
@dax-side
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants