Ai Coding Tools

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

By BTW Team4 min read

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

Building an app can often feel like a daunting task, especially for indie hackers or solo founders juggling multiple side projects. But what if I told you that with the right tools and a bit of guidance, you could leverage GPT-4 to create a simple app in under two hours? In 2026, advances in AI coding tools have made this possible, and I’m here to walk you through the process step-by-step.

Prerequisites: What You Need Before You Start

Before diving in, make sure you have the following:

  1. OpenAI Account: You need access to the GPT-4 API. Pricing starts at $0 for limited usage, with paid plans from $20/month for higher limits.
  2. Code Editor: I recommend Visual Studio Code (free).
  3. Node.js Installed: This will allow you to run your app locally. Get it from nodejs.org.
  4. Basic JavaScript Knowledge: Familiarity with variables, functions, and asynchronous programming is helpful.

Step 1: Set Up Your Environment (15 Minutes)

  1. Install Node.js: Follow the instructions on the Node.js website to download and install.
  2. Create a New Project: Open your terminal and run:
    mkdir my-gpt-app
    cd my-gpt-app
    npm init -y
    
  3. Install Required Packages: You’ll need some packages to interact with the GPT-4 API:
    npm install axios express dotenv
    

Step 2: Create Your App Structure (30 Minutes)

  1. Create the Main Files:

    • index.js: This will be your main server file.
    • .env: Store your OpenAI API key here.
  2. Setup Basic Express Server in index.js:

    const express = require('express');
    const axios = require('axios');
    require('dotenv').config();
    
    const app = express();
    const PORT = process.env.PORT || 3000;
    
    app.use(express.json());
    
    app.listen(PORT, () => {
        console.log(`Server is running on http://localhost:${PORT}`);
    });
    

Step 3: Integrate GPT-4 API (30 Minutes)

  1. Create a Route to Handle Requests: In index.js, add the following route to interact with GPT-4:

    app.post('/generate', async (req, res) => {
        const { prompt } = req.body;
        try {
            const response = await axios.post('https://api.openai.com/v1/chat/completions', {
                model: "gpt-4",
                messages: [{ role: "user", content: prompt }]
            }, {
                headers: {
                    'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`
                }
            });
            res.json(response.data.choices[0].message.content);
        } catch (error) {
            res.status(500).send("Error generating response");
        }
    });
    
  2. Test Your API: Start your server with node index.js and use Postman or curl to send a POST request to http://localhost:3000/generate with a JSON body containing a prompt.

Step 4: Create a Simple Frontend (30 Minutes)

  1. Create an HTML File: Create index.html:

    <!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>Simple GPT-4 App</h1>
        <textarea id="prompt" rows="4" cols="50"></textarea><br>
        <button id="generate">Generate</button>
        <pre id="response"></pre>
        <script>
            document.getElementById('generate').onclick = async () => {
                const prompt = document.getElementById('prompt').value;
                const res = await fetch('/generate', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ prompt })
                });
                const data = await res.json();
                document.getElementById('response').textContent = data;
            };
        </script>
    </body>
    </html>
    
  2. Serve the HTML File: Modify your Express server to serve this file. Add the following line in index.js:

    app.use(express.static('.'));
    

Troubleshooting: What Could Go Wrong

  • API Key Issues: Ensure your API key is correctly set in the .env file.
  • CORS Errors: If you're testing from a different origin, you may need to enable CORS in your Express app.
  • Rate Limits: Be aware of the OpenAI API rate limits. If you exceed them, you’ll get errors.

What's Next?

Once your app is running, consider expanding its functionality. You could add user authentication, store previous prompts, or even deploy it using platforms like Vercel or Heroku.

In our experience, the next logical step is to integrate a database like MongoDB to save user interactions. This can evolve your simple app into a more robust tool.

Conclusion: Start Here

Building a simple app with GPT-4 in under two hours is entirely achievable. With the combination of Node.js and Express, you can create a functional prototype that leverages powerful AI capabilities. If you’re ready to dive in, grab your tools and start coding!

What We Actually Use

  • OpenAI API: For generating responses.
  • Express: To create the server.
  • Axios: For making HTTP requests.
  • Node.js: The runtime environment.

Follow Our Building Journey

Weekly podcast episodes on tools we're testing, products we're shipping, and lessons from building in public.

Subscribe

Never miss an episode

Subscribe to Built This Week for weekly insights on AI tools, product building, and startup lessons from Ryz Labs.

Subscribe
Ai Coding Tools

How to Confidently Integrate AI Coding Tools into Your Workflow in 30 Minutes

How to Confidently Integrate AI Coding Tools into Your Workflow in 30 Minutes The buzz around AI coding tools is loud, but integrating them into your workflow can feel daunting. As

Jun 29, 20264 min read
Ai Coding Tools

Supabase vs Firebase: Which AI Coding Tool is Best for Your Next Project?

Supabase vs Firebase: Which AI Coding Tool is Best for Your Next Project? As a solo founder or indie hacker, choosing the right backend service for your project can feel overwhelmi

Jun 29, 20264 min read
Ai Coding Tools

5 Powerful AI Coding Tools for Beginners in 2026

5 Powerful AI Coding Tools for Beginners in 2026 As a beginner in coding, diving into software development can feel overwhelming. There's a multitude of languages, frameworks, and

Jun 29, 20264 min read
Ai Coding Tools

How to Boost Your Code Quality in 30 Minutes with AI Tools

How to Boost Your Code Quality in 30 Minutes with AI Tools (2026) As a solo founder or indie hacker, you know that code quality can make or break your product. Bad code leads to bu

Jun 29, 20264 min read
Ai Coding Tools

2026 Face-off: GitHub Copilot vs Codeium – Which is Better for Freelancers?

2026 Faceoff: GitHub Copilot vs Codeium – Which is Better for Freelancers? As a freelancer, you’re always on the lookout for tools that can save you time and increase your producti

Jun 29, 20264 min read
Ai Coding Tools

Lovable vs Bolt.new: Which AI Tool Offers Faster App Prototyping?

Lovable vs Bolt.new: Which AI Tool Offers Faster App Prototyping? (2026) As indie hackers and solo founders, we often find ourselves racing against the clock to get our app ideas o

Jun 29, 20264 min read