Doing Serious Backend Development on your Phone
Tags: webdev, android, node, github
Published: 2020-07-27 09:41:57

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**](https://play.google.com/store/apps/details?id=com.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](https://play.google.com/store/apps/details?id=com.sn.restandroid). 

## 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](https://download.apkpure.com/b/apk/aW8udGVtcGFnZS5kb3J5bW9uZ29fNF80ZGIwNWM0ZQ?_fn=RG9yeSBtb25nb0RCIFNlcnZlcl92MC4xLjNfYXBrcHVyZS5jb20uYXBr&as=b2d437001f8baff8613d816b48b2af215f1e78ed&ai=868001597&at=1595832437&_sa=ai%2Cat&k=b6a3892a90cb3). 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](https://dev-to-uploads.s3.amazonaws.com/i/nzbxrt0wwqrlf9ph9aun.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/iojrmuo11b50im5krfg4.png)

>`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](https://dev-to-uploads.s3.amazonaws.com/i/frjj5asp30zcikdmkcsf.png)

## **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](https://dev-to-uploads.s3.amazonaws.com/i/uama45x11rhv8i1ft3yk.png)

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](https://dev-to-uploads.s3.amazonaws.com/i/8tt984u6nr1ket59d06r.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/15fc4gbaon3zapps3nuq.png)


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](https://dev-to-uploads.s3.amazonaws.com/i/pm097kfarg987s4fhxkd.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/i/baz25zyxvc0qf2bw0y94.png)

You will the be shown a response from the server

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3t05q2k23hhlrk4k39ku.png)


**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.