A Primer on Deploying Personal Projects for Free
A look at how you can deploy personal projects for absolutely free, no strings attached
Hey, everyone!
So it's the end of 2022 and now more than ever, it seems like new developers are being expected to have a portfolio of projects that they can present to a potential employer. More often than not, it'd help to have a way to view the project deployments easily. That being said, unless you're trying to specifically run a Javascript front-end framework or just a static front-end website, a lot of hosts will charge you a small fee for you to run your project on their hosting, depending on what you need for your project.
This of course then begs the question: what are all the ways that (especially more junior) developers can deploy their projects for free? It's fairly evident at the moment that if you're running a Javascript front-end web application, you could easily host that on a huge platform like Vercel or Netlify as the site simply builds into a static front-end - simply push code to a GitHub repo, then sign up for one of the aforementioned platforms and deploy from GitHub (or you could use the respective platform's command-line interface which doesn't require Github). If you're running something like Next.js on Vercel, the site will simply take the API files as serverless functions for you so you don't have to do any of the work yourself. The main issue is trying to deploy projects that have a back-end.
The first option you could do would be to simply self-host. You could technically do that if you wanted to and you can use any feature you want as you're the host, but on the other hand, you need a private computer or server that will stay on 24/7. Unless you have money waiting to be burned or you have an actual use case (like a PLEX server), I don't think that would be necessarily something you'd be rushing to do in the current economic climate.
The second option would be to use a free service like Cyclic. This is the typical route that you'd probably try to go and it's a respectable option. One of the problems I've also found with typical back-end service hosting though is that they sometimes don't have a very generous free plan, so your hosting can sometimes die mid-month like on Railway because you've run out of free credits, which isn't ideal. You can't really blame them though, as some hosts mainly use the free tier as a gateway into their paid plans; as they say, it is what it is.
Thankfully, there are some apps like shuttle which strive to be great cloud-native development platforms by providing a generous free tier. It should be said though that if you want to use shuttle you will more than likely want to learn Rust before using it as it's a Rust-native platform. There's a lot of great documentation on the website showing how you can easily make different services with little fuss, but needless to say, the hurdle is still there and if you're still trying to get to grips with your main programming language at the moment it might not be ideal.
Our third option, however, which I believe to be a great alternative, is to use serverless functions. Serverless functions (also otherwise known as "AWS Lambda functions") are standalone functions that are run from a server when a user hits an endpoint, and although AWS Lambda was originally announced in November 2014, it's steadily picking up traction as the hot new thing because it's environmentally green, it saves server owners money, and more importantly, that means you save money because they can afford to lower their prices.
At the moment, if you use any of the major languages, the platforms that do allow serverless functions will either support your language or there will typically be a community-maintained runtime (there is even an AWS Lambda runtime for Erlang!). Vercel officially supports Go, Python, Ruby and Node.js, with AWS additionally supporting Java and C# so if you don't use any of these languages you'll need to use the community runtime. Not a bad thing mind you, but just something to keep in mind.
Let's have a quick look at what a serverless function on Vercel would look like using Node.js and Express:
// requires express and uuid as dependencies to work
const app = require('express')();
const { v4 } = require('uuid');
// when you visit this route, return a link to an individual item slug
app.get('/api/items', (req, res) => {
const path = `/api/item/${v4()}`;
// cache the results to reduce computing time
res.setHeader('Content-Type', 'text/html');
res.setHeader('Cache-Control', 's-max-age=1, stale-while-revalidate');
res.end(`Hello! Go to item: <a href="${path}">${path}</a>`);
});
// return item slug
app.get('/api/item/:slug', (req, res) => {
const { slug } = req.params;
res.end(`Item: ${slug}`);
});
// health check route
app.get('/api/health', (req, res) => {
res.status(200).end("OK");
})
module.exports = app;
We'll want to create a vercel.json
to redirect all API routes to this file, since this is where all of our routes are held:
{
"rewrites": [{ "source": "/api/(.*)", "destination": "/api" }]
}
As you can see, this looks pretty much the same as regular code for a regular Express server, except you're using "end" instead of "send" as we're currently not sending any data with our responses. This is extremely helpful for us, as Express is a very commonly used framework in Node.js and we don't have to attach much boilerplate. You could pretty much just launch the project here and the routes should just work.
What's more, we can add static HTML by simply adding a public
folder to the root of the project, no boilerplate required, which is great for us as we can simply export HTML from another project or create a project within the root of a project that uses something like React, then export the HTML to the public
folder and it should "just work".
If you're trying to use a database, then thankfully you're in luck as there are many free services out there that offer databases. You could use Supabase, Firebase's open-source cousin; you could try Fly.io which although requires a credit card to initially set up, doesn't cost anything and the credit card verification is mainly there to discourage people trying to set up free bot mining farms. MongoDB Atlas is also free and should offer more than enough space for you to get a free personal project going. Airtable is another one that I've found to be pretty good and is also a no-code solution with API integration.
I hope this article has been helpful to you! As you can see, there are plenty of ways you can get your projects out there for completely free without needing to pay a single penny. It has never been easier to deploy a project than it has been up until now; the only thing left is to decide what to build.