DEV Community

JavaScript Joel
JavaScript Joel

Posted on

Getting node.js and Express up and running on my... phone?

I installed Termux from the Play store. It's free and doesn't require root access. Sorry but if you have an iPhone, go fish.

The first thing I always do is check for updates by running these commands. If you have been away from your terminal for a while, it's good to run them again.



apt update
apt upgrade


Enter fullscreen mode Exit fullscreen mode

To extended the keyboard to give you options to keys like ESC, HOME, END, TAB, etc. Swipe from left to right to open the Termux menu and long press on the KEYBOARD word.

Termux screenshot of keyboard

Install nodejs, curl, and git. I know for sure I'll need these.



apt install nodejs curl git


Enter fullscreen mode Exit fullscreen mode

Install your favorite editor. vi is already installed, but I like nano.



pkg install nano


Enter fullscreen mode Exit fullscreen mode

Termux running nano with JavaScript source

I had to fix npm so that I could install packages globally.



nano ../usr/lib/node_modules/npm/node_modules/worker-farm/lib/farm.js


Enter fullscreen mode Exit fullscreen mode

set maxConcurrentWorkers to 1.

I always create a dev directory to keep all my projects.



mkdir dev
cd dev


Enter fullscreen mode Exit fullscreen mode

Time to give it a spin

Let's fire up an example Express app to see if this thing will go.



git clone https://github.com/joelnet/MojiScript.git
cd MojiScript/examples/express-static-files
npm ci
npm start


Enter fullscreen mode Exit fullscreen mode

Screenshot of Termux running an express app

Okay, it says it's listening on port 3000, but I have been lied to before.

Screenshot of a browser running express on Android

Awesome! Looks like it really works!

Notes

I could get n to install, but it didn't have access to /usr directory and fails. This wasn't important to me at this moment, so I didn't dig into a fix. Maybe if you know you can let me know in the comments.

Not all packages are compatible. So this isn't going to be replacing my dev machine any time soon. But it's nice to be able to tinker on the go.

Summary

I was able to get node and express up and running on my Android phone using Termux. The setup is pretty fast and straight forward. I was actually surprised at how easy this was.

I use this setup to run some quick JavaScripts when I am not around a computer. This happens more than I would like to admit.

Where should I take this next? Let me know what you would do with this setup in the comments!

I did get WarriorJS up and running too!

WarriorJS running on Termux

If you love Functional JavaScript, follow me here or on Twitter @joelnet!

Cheers!

Top comments (11)

Collapse
 
sangowen profile image
sangowen • Edited

Termux is really fun! Just my 2 cents, I've installed sshd, mariadb and host a local gitea. With gitea I can push my dotfiles & personal wiki on my laptop into the repos as a backup through ssh.
Recently there is another promising project called UserLAnd. It even lets you apt install straight from debian/ubuntu repo without root. I managed to duplicate my i3wm & all of the terminal functionality I have in my laptop (urxvt,oh-my-zsh,compton,rofi,ranger...). Here's a screenshot of the TigerVNC session.
Hope everyone have fun playing with these awesome apps!
pic

Collapse
 
joelnet profile image
JavaScript Joel

That's Awesome!!!

I definitely have just started to play with this but see so many possibilities.

I'm curious about your gitea + ssh to push files. I have another project where I need to sync files with a remote machine s and I have been looking into different tools to do this.

Could you describe your setup and how it works?

Cheers!

Collapse
 
sangowen profile image
sangowen • Edited

This is the record I left in my wiki a few months ago. A small part of the instruction (mostly step 5 ~ 6) are SQL commands or instead only descriptive.

Setup:

  1. install termux, sshd, go, make

    • pkg install sshd golang-1.10 make
  2. put public key into .ssh/authorized_keys

    • cat ~/.ssh/ssh_host_rsa_key.pub >> ~/.ssh/authorized_keys
  3. set GOPATH & put lib & GOPATH/bin into PATH

    • export GOPATH="/data/data/com.termux/files/home/go/"
    • export PATH="$PATH:/data/data/com.termux/files/home/go/src/github.com/jteeuwen/go-bindata/"
    • export PATH="$PATH:/data/data/com.termux/files/usr/lib/go"
    • export PATH=$PATH:$(go env GOPATH)/bin
  4. install mariadb

    • pkg install mariadb
    • mysql_install_db
  5. maybe change root password for mariadb

    • stop mysqld
    • mysqld_safe --skip-grant-tables --skip-networking &
    • mysql -u root
    • FLUSH PRIVILEGES;
    • ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
    • stop mysqld again
    • restart
  6. create gitea database

    • CREATE DATABASE gitea DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
  7. download & build gitea go package

    • go get -d -u code.gitea.io/gitea
    • cd $GOPATH/src/code.gitea.io/gitea
    • make generate all
  8. ssh into itself to get a valid username for gitea installation

    • ssh 192.168.43.1 -p 8022
  9. start gitea

    • cd $GOPATH/src/code.gitea.io/gitea
    • ./gitea web
  10. open localhost:3000 with browser and install with mysqldb

  11. create user, repo

  12. currently I haven't fix git ssh path shown in UI, ssh can only access by:

    • git remote add phone ssh://u0_a238@192.168.43.1:8022/data/data/com.termux/files/home/gitea-repositories/[gitea_username]/[reop_name].git
    • git push -u phone master
Collapse
 
albizures profile image
Jose Albizures

I did this some time ago and it's pretty cool! You also can activate your phone hotspot and connect another phone to that network, and see your changes there. I tried with react-create-app back then and the livereload makes this workflow a lot easier. Keep an eye to your node_module size though 🤣

Collapse
 
keziahmoselle profile image
Keziah

Niice xD

Collapse
 
joelnet profile image
JavaScript Joel

That sounds cool. It would be interesting to setup remote debugging also.

Collapse
 
cripstian profile image
Cristian Popescu

This is pretty cool, I have to admit. I love the fact that you can test almost all your sudden ideas and put them into practice, there are always such ideas, as you state.
Ideas that if you don't get a quick test on, you will not be able to go through with you subway way home 😁.
I will defenetely try it and see what's up for installing.

Thank you.

Collapse
 
joelnet profile image
JavaScript Joel • Edited

For sure. I love using it to run quick expressions like:

node -p "<expression>"
Collapse
 
keziahmoselle profile image
Keziah

Thank's ! That's really useful

Collapse
 
joelnet profile image
JavaScript Joel

I use this all the time. Next, maybe I'll see if I can get a Docker container started on it.

Collapse
 
keziahmoselle profile image
Keziah

Nice ! Gl