Where Your Code Runs — Browser, Server, and Phone Apps

This article is part of the IT Foundations course, which builds up from scratch the practical IT knowledge you need at a minimum for programming and vibe coding.
The same code behaves differently inside a browser, inside a server, and on a phone's OS. Diagrams trace how you choose between a web app and a native app.

This article covers where the code you write runs.

There are three places it runs: inside the browser, inside the server, and inside the app installed on a phone.

The my-app code you wrote runs in three separate places
my-appcodeindex.htmlapp.jsserver.jsreserve.dbmy-appfor iPhoneInside the user'sbrowserInside thepublic serverOn the phone'sOSArrives whena URL is openedNever leavesInstalled fromthe store
One group on the left splits into three branches on the right. Within the same my-app, the place a file runs and the way it reaches users differ.

Web app code runs in two places: the browser and the server

The software that reads HTML on the user's device and draws the screen is the browser, and a computer set up to accept requests at any time is a server.

The common browsers are Chrome, Safari, Edge, and Firefox.

The language a browser can read and run directly is JavaScript.

my-app is made of four files: the two for the screen are the frontend, and server.js, which takes bookings, is the backend.

When a user opens the URL, only the two screen files reach the device.

How the files of a published my-app are placed
The user's device
Browser
  • index.html — the shape of the booking screen
  • app.js — what happens when the button is pressed
  • Users can open and read the contents of both
Public server
node server.js
  • Runs the code that takes bookings
  • Never reaches the device, so it is not read
reserve.db
  • The file the booking data is written to
Only index.html and app.js reach the user's device. server.js and reserve.db never leave the public server.

Even within the same my-app files, the place they run splits into two frames.

Only index.html and app.js reach the device, and after that, only data passes between the two frames.

Of the next three lines, the middle one exists only inside the browser, and the last one exists only inside the server runtime.

console.log("Book");
console.log(navigator.language);
console.log(process.version);

Run these three lines inside the browser, and the results come out like this.

The same three lines give different results depending on where the feature exists
console.log("Book")navigator.languageprocess.versionExists everywhereExists onlyin the browserExists only in theserver runtimeBookja and so on:the browser languageprocess isnot defined
The left is the line you wrote, the middle is where that feature is provided, and the right is the result when it runs in the browser. Only the bottom one calls a feature the browser does not have.

Web app code splits into two places

index.html and app.js, which build the screen, reach the user's device and run inside the browser.

server.js, which takes bookings, never leaves the public server, so text you do not show to others goes on that side.

To make it usable on a phone, you either keep it a web app or build a native app

Phones have browsers too.

my-app runs as it is if you open the URL in a phone browser.

That is the first way, and there is no need to rebuild the code.

The software that manages app startup, the screen, communication, and files inside a device is the OS, which on a phone is iOS or Android.

The second way is a native app — an app put directly on the OS and run there — which you build separately for iPhone and for Android and deliver through the App Store and Google Play.

Putting an app on a device so that it can be started from the OS is installing it.

Inside a phone — native apps sit on top of the OS
The user's phone
OS (iOS / Android)
my-app (the installed app)
  • Files installed from the App Store
  • Started from the home screen icon
Browser
  • Opening the URL runs the web app
  • index.html and app.js arrive here
The outside is one phone. On top of the OS sit the installed my-app and the browser. If it stays a web app, it runs inside that browser.

As the diagram shows, a native app sits on top of the OS, while a web app runs on top of the browser inside that OS.

A program or device that sends requests to a server is called a client, and the side that runs on the device is also called client-side, and the side that runs on the server, server-side.

From either client, requests gather in the same place
Phonebrowsermy-app installedon the phonenode server.js onthe public serverreserve.dbRequestRequestSave
Arrows from the two on the left gather in the center. Whether it comes from the browser or from the app installed on the phone, the same server.js receives it.

You choose between them by lining up the strengths and weaknesses.

What to look atWeb appNative app
Device features you can useOnly what the browser providesBroad access to OS features
Where people find itSearch engines and shared URLsSearch in the App Store or Google Play
Effort to deliver to usersJust have them open a URLPass store review, then have them install it
Time for a fix to reach usersThe next time they open the URLWait until the user updates
Number of codebases to buildOne works on both iPhone and AndroidBuild separately for iPhone and Android

A browser gives you only the features the browser provides, and when you want device features beyond that, you build a native app.

The same goes for when you want people to find you through store search, and if neither applies, you keep it a web app.

There is also a way to build apps for several operating systems from a single codebase, and the name for it is covered in the next article.

However you deliver it, server.js is shared

Keep it a web app, and it runs just by opening the URL in a phone browser.

A native app is built separately for iPhone and Android and installed from a store, but whichever you choose, server.js and reserve.db stay on the public server.

What differs between running on your own machine and running live

The my-app you built can still be opened only from your own computer.

The inside of your own computer, seen as a place to run code, is called local.

The number at the end of the http://localhost:3000 you open locally is there to tell destinations apart inside the same computer, and it is covered in this course's article "What Happens When You Enter a URL."

Inside the frame is your own computer, a single machine, and the browser, server.js, and reserve.db are all in there.

Once you publish, the contents of this one machine split into two places, but what fills each role does not change.

Same roleLocalAfter publishing
Runs the screenThe browser on your computerUser's browser
Takes bookingsnode server.js on your computernode server.js on the public server
Stores the datareserve.db on your computerreserve.db on the public server
URL the user openshttp://localhost:3000The public server's URL

The names of the files that run are the same locally and after publishing.

Moving the four files together to a public server outside your own computer is deployment.

The four files move to the public server, and the only thing left on your computer is the browser.

Open the same example.com from any device, and the same screen appears.

As long as it stays local, it does not accept requests from outside, so other people cannot use it from their devices.

localhost:3000 points at the device you typed it on, so typing it on a colleague's phone does not reach your computer.

What the work of publishing involves is covered in this course's "Deployment and Environment Variables — From Working Locally to Going Live."

Change where you put it, and you change who can use it

The my-app you got running by following a beginner book's steps can be opened only from inside your own computer — that is, locally.

Move the four files to a public server and other people's devices can open it too, and that work is deployment.

QUIZ

Knowledge Check

Answer each question one by one.

Q1Where does the screen code of a web app (index.html and app.js) run?

Q2Which way makes the my-app you built usable on a phone without rebuilding the code?

Q3What do you need in order to make a my-app that runs locally usable from other people's devices?