Termux
Recently I've found a very neat Adnroid
app which I can run on my Chromebook - Termux- "Termux combines powerful terminal emulation with an extensive Linux package collection."
In essence after installing it you will have a nice Linux distro on your Android device without root.
In my case I've decided to try if I can use Termux for Node development.
Node development
The initial plan was to install node
inside Termux and to use it to install npm
packages and run code.
After installing the app there is a need to run termux-setup-storage
command from within Termux to get access to the Chromebook storage. After this I've tried to install some packages directly in the Downloads
folder but unfortunately because Termux do not provide root access I was unable to install them.
The plan was changed then. I've decided to install npm
packages inside Termux
, write my code inside some editor (like Caret) and save it somewhere in the Downloads
folder and then move only the code file(s) into Termux
where the npm
packages are installed and the server is running.
Installing the packages inside Termux and copying manually the main js file worked just fine but this needed to be more automated.
Gulp
Since I was going to use Node I've decided to use Gulp for the automated copy (and for the other tasks as well). I'm using the code below to sync the files between source
folder and destination
folder with gulp-newer plugin (there are few other plungs that can be used as well)
var gulp = require('gulp');
var newer = require('gulp-newer');
var source = '/data/data/com.termux/files/home/storage/downloads/nodetest';
var destination = '../nodetest'
gulp.task('sync', function() {
return gulp.src(source + '/**/*')
.pipe(newer(destination))
.pipe(gulp.dest(destinatioin));
});
gulp.task('watch', function() {
gulp.watch(source + '/**/*', ['sync']);
});
After starting the gulp watch
task every time file in the source
folder is changed it will be moved in the destination
folder.
nodemon
I've also installed nodemon so after every file change the server will be restarted automatically. In my case I've used --delay 2.5
as a parameter in nodemon
to delay the restart with 2.5 seconds - just to make sure that all files are copied.
Result
If Termux
is used on phone or tabled to view your web app you just need to navigate to http://localhost
. For Chromebooks the situation is a bit more different. You need to find the ip
address of the Android instance. This can be done by executing the following command from Termux
:
ip addr list
And look for the non-localhost address. (in my case this was 192.168.254.2
)
Conclusion
In conclusion I can say that Termux
opens a lot of possibilities for Chromebook/Android developers without entering to Dev mode.
Hope you like it!
Stefan