Ai Coding Tools

How to Build a Simple App with GPT-4 in Under 2 Hours

By BTW Team4 min read

Comparing tools? See the AI tools tested on the show.

In short

A step-by-step guide for beginners on how to leverage GPT-4 to create a functional app in less than two hours, complete with coding snippets and tips.

If you’re a solo founder or indie hacker looking to leverage AI in your projects, GPT-4 is a powerful tool that can help you build a functional app quickly. The thought of coding might seem daunting, but with the right approach, you can have a simple app up and running in less than two hours. Let’s dive into how you can do this, what tools you’ll need, and the potential pitfalls to watch out for.

Prerequisites: What You Need to Get Started

Before we jump into the build, here’s what you’ll need:

  • A basic understanding of coding: You don’t need to be a pro, but familiarity with concepts like variables and functions will help.
  • An OpenAI API key: Sign up at OpenAI and get access to GPT-4. Pricing starts at $0.003 per token, which is quite affordable for small projects.
  • A code editor: We recommend Visual Studio Code, which is free and feature-rich.
  • Node.js installed: This will allow you to run your app locally. Installation is straightforward and takes about 10 minutes.

Step 1: Setting Up Your Environment

  1. Install Node.js: Head to nodejs.org and download the latest version. Follow the installation instructions for your OS.
  2. Create a new project directory: Open your terminal and run:
    mkdir my-gpt-app
    cd my-gpt-app
    npm init -y
    
  3. Install necessary packages: You’ll need axios for API calls and express for creating a simple web server. Run:
    npm install axios express
    

Step 2: Writing Your App

Now, let’s create a simple Express server that interacts with GPT-4. Here’s a step-by-step breakdown:

  1. Create a file named server.js:

    const express = require('express');
    const axios = require('axios');
    const app = express();
    const PORT = process.env.PORT || 3000;
    
    app.use(express.json());
    
    app.post('/api/gpt', async (req, res) => {
        const userInput = req.body.input;
        try {
            const response = await axios.post('https://api.openai.com/v1/chat/completions', {
                model: 'gpt-4',
                messages: [{ role: 'user', content: userInput }]
            }, {
                headers: {
                    'Authorization': `Bearer YOUR_API_KEY`
                }
            });
            res.json(response.data.choices[0].message.content);
        } catch (error) {
            res.status(500).send('Error communicating with GPT-4');
        }
    });
    
    app.listen(PORT, () => {
        console.log(`Server is running on http://localhost:${PORT}`);
    });
    
  2. Replace YOUR_API_KEY with your actual OpenAI API key.

  3. Start your server: Run the following command in your terminal:

    node server.js
    
  4. Test your API: Use Postman or curl to send a POST request to http://localhost:3000/api/gpt with a JSON body like:

    { "input": "What is the capital of France?" }
    

Step 3: Building Your Frontend (Optional)

If you want a simple frontend to interact with your app, create an index.html file:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>GPT-4 App</title>
</head>
<body>
    <h1>Ask GPT-4</h1>
    <input type="text" id="userInput" placeholder="Type your question...">
    <button onclick="sendRequest()">Send</button>
    <p id="response"></p>

    <script>
        async function sendRequest() {
            const input = document.getElementById('userInput').value;
            const response = await fetch('/api/gpt', {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify({ input })
            });
            const data = await response.json();
            document.getElementById('response').innerText = data;
        }
    </script>
</body>
</html>

Just open this HTML file in your browser, and you can start asking questions!

What Could Go Wrong

  • API Errors: If you encounter errors when calling the OpenAI API, check your API key and usage limits.
  • CORS Issues: If you access the server from a different origin, set up CORS in your Express app (using the cors package).
  • Rate Limits: OpenAI has usage limits; be mindful of how many requests you’re making.

What's Next?

Now that you have a basic app running, consider enhancing it by:

  • Adding user authentication.
  • Storing conversations in a database (like Firebase or MongoDB).
  • Deploying your app using platforms like Heroku or Vercel.

Conclusion: Start Here

Building a simple app with GPT-4 can be done in under two hours if you follow this guide. While the basic setup is straightforward, the scalability and complexity depend on your future needs. Start with this foundational app, and expand as you learn more.

What We Actually Use

We use a mix of tools for building with GPT-4, including:

  • OpenAI API for AI functionalities.
  • Express for server-side handling.
  • Axios for API requests.

These tools keep our stack lightweight and efficient, perfect for quick iterations.

Watch real AI builds every week

Built This Week is a weekly podcast where Jordan Metzner and Sam Nadler build something real with AI every episode, test new AI tools and talk with founders who build with AI.

See the tools

Watch real AI builds every week

Built This Week is a weekly podcast where Jordan Metzner and Sam Nadler build something real with AI every episode, test new AI tools and talk with founders who build with AI.

See the tools
Ai Coding Tools

3 AI Coding Tools That Are Overrated (and Why You Should Avoid Them)

3 AI Coding Tools That Are Overrated (and Why You Should Avoid Them) In the everevolving landscape of AI coding tools, it's easy to get swept up in the hype. As indie hackers and s

Nov 30, 20263 min read
Ai Coding Tools

5 Ways AI Coding Tools Can Accelerate Your MVP Development in 2026

5 Ways AI Coding Tools Can Accelerate Your MVP Development in 2026 In 2026, the landscape for indie hackers and solo founders has evolved significantly, especially with the advent

Nov 26, 20264 min read
Ai Coding Tools

5 AI Coding Tools That Make Legacy Code Feel Brand New in 2026

5 AI Coding Tools That Make Legacy Code Feel Brand New in 2026 If you’re a developer stuck maintaining legacy code, you know the frustration. It’s like navigating a maze blindfolde

Nov 23, 20264 min read
Ai Coding Tools

10 AI Coding Tools That Will Save You Hours of Debugging in 2026

10 AI Coding Tools That Will Save You Hours of Debugging in 2026 Debugging can feel like a neverending cycle of frustration. Whether you're a solo founder or an indie hacker, spend

Nov 18, 20265 min read
Ai Coding Tools

10 Common Mistakes When Using AI Coding Tools for MVP Development

10 Common Mistakes When Using AI Coding Tools for MVP Development As a founder in 2026, you’re likely aware that AI coding tools can significantly speed up the MVP development proc

Nov 16, 20264 min read
Ai Coding Tools

5 AI Coding Myths Every Beginner Developer Should Ditch in 2026

5 AI Coding Myths Every Beginner Developer Should Ditch in 2026 As a beginner developer, you’ve probably come across a ton of buzz surrounding AI coding tools. But with all the hyp

Nov 12, 20263 min read