Ai Coding Tools

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

By BTW Team4 min read

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

Building a web app can feel overwhelming, especially if you're new to coding or working with AI tools. But what if I told you that you could create a simple web app using GPT-4 in under 2 hours? In 2026, the landscape of AI coding tools has evolved significantly, making it easier for indie hackers and solo founders to leverage powerful technology without becoming a coding expert.

In this guide, I'll walk you through the process step-by-step, share the tools you’ll need, and highlight the trade-offs along the way. Let’s dive in!

Prerequisites: What You Need Before Starting

  1. Basic Understanding of HTML/CSS/JavaScript: You don’t need to be a pro, but familiarity with these languages will help.
  2. OpenAI API Key: You'll need access to GPT-4. Sign up at OpenAI and get your API key (pricing starts at $0.003 per token).
  3. Node.js Installed: If you don’t have Node.js, download and install it from nodejs.org.
  4. A Code Editor: Use Visual Studio Code or any text editor of your choice.
  5. A GitHub Account: Optional but useful for version control and collaboration.

Step 1: Setting Up Your Environment (15 minutes)

  1. Create a New Directory: Open your terminal and create a new folder for your project:

    mkdir gpt-web-app
    cd gpt-web-app
    
  2. Initialize a Node.js Project:

    npm init -y
    
  3. Install Required Packages:

    • Express: A web framework for Node.js.
    • Axios: For making API requests to OpenAI.
    npm install express axios dotenv
    
  4. Create Essential Files:

    • index.js: Your main application file.
    • .env: To store your OpenAI API key securely.

Step 2: Building the Web App (1 hour)

  1. Set Up Your Server: Open index.js and add the following code:

    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.use(express.static('public'));
    
    app.post('/api/gpt', async (req, res) => {
        try {
            const response = await axios.post('https://api.openai.com/v1/chat/completions', {
                model: 'gpt-4',
                messages: [{ role: 'user', content: req.body.prompt }]
            }, {
                headers: {
                    'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`
                }
            });
            res.json(response.data.choices[0].message.content);
        } catch (error) {
            res.status(500).send('Error communicating with OpenAI');
        }
    });
    
    app.listen(PORT, () => {
        console.log(`Server is running on http://localhost:${PORT}`);
    });
    
  2. Create a Simple Frontend: In the public folder, 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 Web App</title>
    </head>
    <body>
        <h1>Simple Web App with GPT-4</h1>
        <textarea id="prompt" placeholder="Type your prompt here..."></textarea>
        <button id="submit">Submit</button>
        <pre id="response"></pre>
    
        <script>
            document.getElementById('submit').onclick = async () => {
                const prompt = document.getElementById('prompt').value;
                const response = await fetch('/api/gpt', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ prompt })
                });
                const data = await response.text();
                document.getElementById('response').innerText = data;
            };
        </script>
    </body>
    </html>
    
  3. Run Your Application: Back in your terminal, start your application:

    node index.js
    

    Visit http://localhost:3000 in your browser, input a prompt, and click submit to see GPT-4 in action.

Step 3: Testing and Troubleshooting (15 minutes)

  • Common Issues:

    • If the server doesn’t start, double-check your code for typos.
    • Ensure your .env file contains the correct API key.
  • What Could Go Wrong:

    • API limits: If you exceed your token limit on OpenAI, you’ll need to manage your usage or upgrade your plan.
    • Network issues: Ensure you have a stable internet connection, as API calls require it.

Step 4: What's Next?

Once you have your simple web app running, consider these enhancements:

  1. Add User Authentication: Use Firebase or Auth0 for user accounts.
  2. Deploy Your App: Use services like Vercel or Heroku for easy deployment.
  3. Expand Functionality: Integrate other APIs or add more features based on user feedback.

Conclusion: Start Here

If you’re looking to build a simple web app quickly, using GPT-4 can be a powerful approach. This setup gives you a solid foundation to iterate on and expand your project. Remember, the key is to keep it simple and focus on what you can build in under 2 hours.

What We Actually Use

For our own projects, we use:

  • Node.js for backend development
  • Express for API management
  • OpenAI API for AI capabilities
  • Vercel for deployment

Building with GPT-4 is both accessible and efficient, and it can yield impressive results with minimal overhead.

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 Integrate AI Tools into Your Development Workflow in 3 Simple Steps

How to Integrate AI Tools into Your Development Workflow in 3 Simple Steps As a solo founder or indie hacker, integrating AI tools into your development workflow can feel overwhelm

Jun 11, 20264 min read
Ai Coding Tools

5 Mistakes Developers Make with AI Tools and How to Avoid Them

5 Mistakes Developers Make with AI Tools and How to Avoid Them As developers, we often get caught up in the excitement of new AI tools, thinking they’ll magically solve our problem

Jun 11, 20263 min read
Ai Coding Tools

How to Code Your First App Using an AI Tool in Just 3 Hours

How to Code Your First App Using an AI Tool in Just 3 Hours If you're a beginner looking to dive into coding but feel overwhelmed by the thought of learning a programming language,

Jun 11, 20264 min read
Ai Coding Tools

5 Best AI Coding Tools for Beginners to Use in 2026

5 Best AI Coding Tools for Beginners to Use in 2026 If you’re a beginner in programming, you might feel overwhelmed by the sheer volume of coding tools available today. The good ne

Jun 10, 20264 min read
Ai Coding Tools

Why Most Developers Overlook Cursor - A Contrarian Take

Why Most Developers Overlook Cursor A Contrarian Take As a developer, you might have seen the buzz around AI coding tools like Cursor. But here's the kicker: many developers are c

Jun 10, 20263 min read
Ai Coding Tools

How to Integrate AI Tools to Boost Your Coding Productivity in 60 Minutes

How to Integrate AI Tools to Boost Your Coding Productivity in 60 Minutes As indie hackers and solo founders, we often find ourselves juggling multiple tasks, and coding can someti

Jun 10, 20264 min read