Ai Coding Tools

How to Build a Simple AI-Powered Web App in Just 2 Hours

By BTW Team4 min read

How to Build a Simple AI-Powered Web App in Just 2 Hours

If you're an indie hacker or a side project builder, you might think that building an AI-powered web app is a daunting task that requires a huge investment of time and resources. But what if I told you that you can build a simple AI web app in just 2 hours? In 2026, with the right tools and a clear plan, it’s entirely possible. Let’s dive into how you can get this done without breaking the bank or your sanity.

Prerequisites: What You Need Before Starting

Before we jump into the building process, you need to have a few things in place:

  1. Basic Coding Knowledge: Familiarity with HTML, CSS, and JavaScript is essential.
  2. An IDE: Use something like Visual Studio Code, which is free and highly effective.
  3. Accounts for AI APIs: Sign up for an AI service like OpenAI or Google Cloud AI (both offer free tiers).
  4. A Deployment Platform: Get an account on platforms like Heroku or Vercel for easy deployment.

Step 1: Set Up Your Development Environment

  • Time Estimate: 15 minutes
  • Download and install Visual Studio Code if you haven’t already.
  • Create a new project folder and initialize it with npm init -y to set up a basic Node.js project.
  • Install necessary packages using npm. You’ll likely need express for your server and any AI API client libraries.
npm install express axios

Step 2: Create the Web App Structure

  • Time Estimate: 30 minutes
  • Create a simple HTML file (index.html) with a form for user input. This will be where users interact with your AI model.
  • Create a basic Express server in server.js to serve your HTML file and handle API requests.

Example Structure:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>AI Web App</title>
</head>
<body>
    <h1>Ask the AI</h1>
    <form id="aiForm">
        <input type="text" id="userInput" placeholder="Ask me anything..." required>
        <button type="submit">Submit</button>
    </form>
    <div id="response"></div>
    <script src="script.js"></script>
</body>
</html>

Step 3: Integrate AI API

  • Time Estimate: 30 minutes
  • Use the AI API to process user input. For example, if you're using OpenAI's GPT model, you can send a request to their endpoint with user input and get a response.

Sample Code in server.js:

const express = require('express');
const axios = require('axios');
const app = express();
app.use(express.json());
app.use(express.static('public'));

app.post('/ask', async (req, res) => {
    const userInput = req.body.input;
    const response = await axios.post('YOUR_AI_API_ENDPOINT', {
        prompt: userInput,
        max_tokens: 100,
    }, {
        headers: {
            'Authorization': `Bearer YOUR_API_KEY`
        }
    });
    res.json(response.data);
});

app.listen(3000, () => console.log('Server running on port 3000'));

Step 4: Frontend Logic

  • Time Estimate: 20 minutes
  • Write JavaScript to handle form submission, send user input to your server, and display the AI's response.

Sample Code in script.js:

document.getElementById('aiForm').addEventListener('submit', async (e) => {
    e.preventDefault();
    const userInput = document.getElementById('userInput').value;
    const response = await fetch('/ask', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({ input: userInput }),
    });
    const data = await response.json();
    document.getElementById('response').innerText = data.choices[0].text;
});

Step 5: Deployment

  • Time Estimate: 25 minutes
  • Choose a deployment platform like Heroku or Vercel. Both offer free tiers.
  • Follow their documentation to deploy your application. For Heroku, you can use the CLI to push your code.
heroku create
git push heroku master

Troubleshooting: What Could Go Wrong

  1. CORS Issues: Ensure your API endpoints are set up to allow requests from your web app’s domain.
  2. API Limitations: Most AI APIs have rate limits. Keep an eye on usage to avoid unexpected costs.
  3. Unexpected Errors: Use console logs to debug your app effectively.

What's Next: Scaling Your Application

Now that you have a working AI-powered web app, consider these next steps:

  • Add More Features: Integrate more complex AI features or additional APIs.
  • User Authentication: Consider adding a user login system if you want to save user interactions.
  • Analytics: Implement analytics to track usage and improve your app based on user feedback.

Conclusion: Start Here

Building a simple AI-powered web app in just 2 hours is not only possible but also a fantastic way to dive into the world of AI. The tools and frameworks available today make it easier than ever for indie hackers to create something meaningful.

What We Actually Use: We typically utilize OpenAI for AI processing due to its robust features and user-friendly API. For deployment, we favor Vercel for its simplicity and seamless integration with frontend frameworks.

If you’re ready to tackle your first AI project, gather your tools and follow this guide. You’ll be surprised at what you can achieve in just a couple of hours!

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 Use GitHub Copilot to Improve Your Code Quality

How to Use GitHub Copilot to Improve Your Code Quality In 2026, developers are still wrestling with the same old problem: how to produce highquality code efficiently. Enter GitHub

May 5, 20264 min read
Ai Coding Tools

Cursor vs Codeium: Which is the Best AI Coding Assistant in 2026?

Cursor vs Codeium: Which is the Best AI Coding Assistant in 2026? As a solo founder or indie hacker, you're probably juggling multiple roles, and the last thing you need is to spen

May 5, 20263 min read
Ai Coding Tools

How to Build a Full-Featured App in 3 Hours Using AI Coding Tools

How to Build a FullFeatured App in 3 Hours Using AI Coding Tools In the fastpaced world of indie hacking, time is often our most limited resource. Imagine being able to build a ful

May 5, 20264 min read
Ai Coding Tools

Bolt.new vs GitHub Copilot: Which AI Tool Suits Your Workflow Better?

Bolt.new vs GitHub Copilot: Which AI Tool Suits Your Workflow Better? As a solo founder or indie hacker, you know that time is your most precious resource. The right coding tool ca

May 5, 20263 min read
Ai Coding Tools

Why GitHub Copilot is Overrated: 6 Reasons You Should Know

Why GitHub Copilot is Overrated: 6 Reasons You Should Know As a solo founder or indie hacker, you’re always on the lookout for tools that can genuinely accelerate your productivity

May 5, 20263 min read
Ai Coding Tools

Why GitHub Copilot is Overrated: The Realities Behind AI-Assisted Coding

Why GitHub Copilot is Overrated: The Realities Behind AIAssisted Coding As a solo founder or indie hacker, the allure of AI tools like GitHub Copilot can be strong. The promise of

May 5, 20264 min read