DEV Community

Cover image for Doing Serious Backend Development on your Phone
Just Patrick
Just Patrick

Posted on

Doing Serious Backend Development on your Phone

Its Finally here guys, as promised. Today we are going to setup your phone for some back end development. I'll walk you through all the tools you need to continue coding your apis on your Phone, on your couch 😎😎. We are going to hook up a rest api with some CRUD functionalities to our MongoDB service RUNNING ON OUR PHONEπŸŽ‰πŸŽ‰.

Replacements

1. Terminal/Linux environment

Its none other than the Legendary Termux app. This app is a terminal emulator that will provide a sort of Linux enviroment/shell(correct me if am wrong though) where we can install NodeJs,Git and Vim. Of course termux has A LOT more capabilities and functions but for today we will just use it for some JS development. I do encourage you dive in more deeper into termux as it is just freaking amazing and has a pretty nice community.

2. Postman

In order to test our routes we will be using an app called REST Api Client which you can download here.

3. MongoDb Compass

For our mongodb service we will be using an app called Dory Mongo which you can also directly download using this link. The developer pulled it down from play store but you can get from apkpure(the website). You can ofcourse just use the connection string from your remote database running on Atlas.

OK, if your done with downloading the apps we can start.

Setting Up Termux

So when you first launch termux you'll be greeted by this screen.

Termux default screen

You can treat these as the bare environment you get after installing Linux. Let's first update termux by running this command apt update && apt upgrade.
As I said we need NodeJs,Git and Vim(optional, if you hate it, nano is preinstalled).
Just run the commands below

pkg install git

pkg install nodejs

***NB: This will install will install the Latest release of Node with for my case is v 14.0.0*

termux node vesrion

pkg install vim

Lets create a shared folder where we will be storing all our project files. I recommend this as the termux files and folders you create in the root directory will not be visible in your Default File Manager.

First give termux access to your storage by running this command

termux-setup-storage

Then lets create our folder in the shared Directory.

cd storage/shared && mkdir Termux

We can now access this folder from Termux and from our File Manager

Alt Text

Initializing our Project

You can just go about this using your normal workflow like mkdir Backend && cd Backend && npm init -y and so on. But to shorten this tutorial i'll just pull some boiler plate code for a Node Mongoose CRUD api from github.

git clone https://github.com/fedosejev/restful-api-express-mongoose.git

cd restful-api-express-mongoose

npm install

This is how the project looks like

project look

To start the server we can run the script node app.js but not yet. We need a mongodb connection silly πŸ˜….

Starting a MongoDB Service

Again this is not necessary if you have a remote mongo service running in the ☁☁. You can just replace the IP and Database name in the connection string with your own.
But lets focus on offline for when your at your grandma's and and there's no network πŸ•.

  1. So open the Dory Mongo app and click on the play button to start the service.
  2. Replace the IP address in your connection string with the one nemo, sorry Dory, is running on and replace the database name part with...you guessed it, A database name of your liking.

Alt Text

Alt Text

Ok, so now we have setup a mongodb service and connected to it. You can now finally start your server(node app.js) πŸŽ‰πŸŽ‰πŸŽ‰πŸŽŠπŸŽŠπŸŽŠπŸŽŠ

Our server is finally running on port 8080 but now we have to test our api to see if we forgot any semicolon in our code(πŸ˜‚Java guys)

Alt Text

Testing our routes

  1. Open the REST Api Client App.
  2. Switch to http on the left of the input field
  3. And Finally enter the address as 127.0.0.1:8080/api/items/
  4. Select POST, enter your Json Data and click Send

Alt Text

You will the be shown a response from the server

Alt Text

NB: Go to the Models folder of the project and see what type of data is expected

You can now run other requests, GET,DELETE,PUT and so on.

Phew we are finally done. That was simple right. "Hey, what was Vim for Bro?". Sorry I almost forgot. Its of course for editing your files from termux. You can 'cd' into your project and run vim . then select the file you want to edit. or just use nano. or even better use Spck editor.

Combine this article with my previous one about spck editor and wallah, You are doing Fullstack Web Developmet on Your Phone

Have a great day.

Top comments (1)

Collapse
 
kmohzaid profile image
KMohZaid

Thanks for Information.

Mongod not working in termux so i search but not get solution.

After reading your this blog i know about Dory Mongo appπŸ™‚
By this i can run mongod & then i can use mongo