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 Boost Your Coding Efficiency with AI Tools in Just One Week

How to Boost Your Coding Efficiency with AI Tools in Just One Week As a solo founder or indie hacker, you know the pain of spending too much time on repetitive coding tasks. If you

Mar 27, 20265 min read
Ai Coding Tools

10 Mistakes When Using AI Coding Tools: Lessons Learned

10 Mistakes When Using AI Coding Tools: Lessons Learned As someone who's spent countless hours experimenting with AI coding tools, I've seen firsthand how they can revolutionize th

Mar 27, 20264 min read
Ai Coding Tools

How to Boost Your Productivity with AI Coding Tools in Two Hours

How to Boost Your Productivity with AI Coding Tools in Two Hours If you're like most indie hackers or solo founders, you know that coding can be a timeconsuming process. Between de

Mar 27, 20265 min read
Ai Coding Tools

How to Use AI Tools to Write Code in 10 Minutes

How to Use AI Tools to Write Code in 10 Minutes (2026) As a solo founder or indie hacker, you've probably felt the pressure of needing to ship code quickly, especially when you're

Mar 27, 20264 min read
Ai Coding Tools

How to Learn Python with AI Tools in Just 4 Weeks

How to Learn Python with AI Tools in Just 4 Weeks Learning Python can feel like a daunting task, especially if you're juggling a side project or running a business. The good news?

Mar 27, 20264 min read
Ai Coding Tools

Why Most Developers Underestimate the Value of AI Coding Tools

Why Most Developers Underestimate the Value of AI Coding Tools in 2026 As a developer, you might find it hard to believe that AI coding tools can actually improve your workflow. Af

Mar 27, 20264 min read