How to create an executable file?

By Prajwal Haniya

Techletter #92 | September 28, 2024

What do you mean by an executable file?

An executable file is a type of file that contains binary code, which instructs the CPU directly to perform specific tasks or run programs. These files are not meant to be read or interpreted, they are compiled and directly executed by the operating system. For example, you can write a program in Python and run it on a system where Python is not installed. (Of course, there are other conditions, keep reading to know about them)

I love the JS ecosystem, but when it comes to creating an executable file it is just a pain. There is no easy way around it. At the time of writing this letter node’s latest version is 22.9 and it supports only the commonJS way of module system. As creating an executable file is still in development, you will be blocked by creating a full-blown executable system.

How to create an executable file?

So, for creating an executable file, I feel Python is way mature and I was able to create and test it successfully for a simple program. So how you can create it?

I have started using Fastapi. So we will use it to start the server

from fastapi import FastAPI
import uvicorn

app = FastAPI()

@app.get("/")
def read_root():
    return {"Hello": "I am an executable file"}

if __name__ == '__main__':
    uvicorn.run(app, host="0.0.0.0", port=8000)

Python makes it a lot easier to create .exe files. Python community has already built a library for doing it. It’s called pyinstaller

With the help of this package, you just have to run one command to create .exe file. (Make sure to install the pyinstaller)

pyinstaller main.py

The executable will be created in the respective dist directory. You can run the .exe with the command ./app

I have explored a lot to create an executable file in JS. But, I am grateful that they are building such possibilities. Once they release it I feel it will be of great use, and many backend applications and distributable binaries can be built around it.