Ai Coding Tools

How to Create a Simple AI-Powered Web Application in Under 2 Hours

By BTW Team4 min read

How to Create a Simple AI-Powered Web Application in Under 2 Hours

Building an AI-powered web application sounds daunting, especially if you're just starting out. The good news? You can actually get a simple one up and running in under two hours. In 2026, with the right tools and a bit of guidance, it's more accessible than ever. Let's dive into how you can make this happen without breaking the bank or losing your sanity.

Prerequisites: What You Need Before You Start

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

  • Basic coding knowledge (HTML, CSS, JavaScript)
  • Node.js installed on your machine
  • A code editor (like Visual Studio Code)
  • An account with a cloud service provider (we'll use Vercel for deployment)

Step 1: Set Up Your Development Environment

First, you'll want to create a new directory for your project. Open your terminal and run:

mkdir my-ai-app
cd my-ai-app
npm init -y

This creates a new Node.js project. Next, install the necessary dependencies:

npm install express body-parser axios
  • Express: A minimal web framework for Node.js.
  • Body-parser: Middleware to handle JSON requests.
  • Axios: For making HTTP requests to AI services.

Step 2: Create Your Basic Server

In your project directory, create a file named server.js. This will house your server code. Here’s a simple setup:

const express = require('express');
const bodyParser = require('body-parser');
const axios = require('axios');

const app = express();
app.use(bodyParser.json());

app.post('/api/generate', async (req, res) => {
  const { input } = req.body;
  // Call AI API here (we'll fill this in later)
  res.json({ output: "AI response here" });
});

app.listen(3000, () => {
  console.log('Server running on http://localhost:3000');
});

Step 3: Integrate an AI API

For this tutorial, we’ll use OpenAI's API, which is straightforward and offers a free tier. Here’s how to set it up:

  1. Sign up for OpenAI: Go to OpenAI and create an account.
  2. Get your API key: After signing up, you’ll find your API key in the dashboard.

Now, update your /api/generate endpoint to call OpenAI:

app.post('/api/generate', async (req, res) => {
  const { input } = req.body;
  try {
    const response = await axios.post('https://api.openai.com/v1/chat/completions', {
      model: "gpt-3.5-turbo",
      messages: [{ role: "user", content: input }],
    }, {
      headers: { 'Authorization': `Bearer YOUR_API_KEY` }
    });
    res.json({ output: response.data.choices[0].message.content });
  } catch (error) {
    res.status(500).send('Error generating response');
  }
});

Replace YOUR_API_KEY with your actual OpenAI API key.

Step 4: Create a Simple Frontend

Create a new file named index.html in your project directory:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI Web App</title>
</head>
<body>
    <h1>AI-Powered Web App</h1>
    <input id="input" type="text" placeholder="Ask me anything...">
    <button onclick="generateResponse()">Submit</button>
    <p id="response"></p>

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

Step 5: Run Your Application

In your terminal, run:

node server.js

Now, you can access your application at http://localhost:3000. Type a question in the input box and hit submit. It should return an AI-generated response.

Step 6: Deploy Your Application

For easy deployment, we'll use Vercel. Here’s how:

  1. Sign up for Vercel: Go to Vercel.
  2. Connect your GitHub account.
  3. Push your code to a GitHub repository.
  4. Import your GitHub project into Vercel and follow the prompts to deploy.

Troubleshooting: What Could Go Wrong

  • API Key Issues: Ensure you’ve copied the API key correctly and that your OpenAI account is active.
  • CORS Errors: If you encounter CORS issues, you may need to set up CORS middleware in your Express app.
  • Deployment Errors: Double-check that all necessary files are included in your GitHub repo.

What's Next?

Now that you have a basic AI-powered web app, consider adding features like user authentication or a more complex frontend using React or Vue.js. You can also explore additional AI APIs for different functionalities.

Conclusion: Start Here

Creating an AI-powered web application in under two hours is entirely feasible with the right tools and setup. I recommend starting with the OpenAI API and Vercel for deployment. Remember, the key is to keep it simple at first and build from there.


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

10 Common Mistakes When Integrating AI Coding Tools into Your Workflow

10 Common Mistakes When Integrating AI Coding Tools into Your Workflow As developers, we’re always on the lookout for ways to streamline our workflow and boost productivity. Enter

Oct 14, 20264 min read
Ai Coding Tools

5 Myths About AI Coding Tools That Could Hurt Your Development Process

5 Myths About AI Coding Tools That Could Hurt Your Development Process As a solo founder or indie hacker, you might be lured by the promises of AI coding tools that claim to simpli

Oct 13, 20264 min read
Ai Coding Tools

5 Common Mistakes Developers Make When Using AI Coding Tools in 2026

5 Common Mistakes Developers Make When Using AI Coding Tools in 2026 As AI coding tools have become an integral part of a developer's toolkit in 2026, many are still stumbling over

Oct 12, 20264 min read
Ai Coding Tools

5 Myths About AI Coding Tools: What Every Developer Should Know in 2026

5 Myths About AI Coding Tools: What Every Developer Should Know in 2026 As we dive into 2026, the landscape of AI coding tools has evolved significantly, yet many developers still

Oct 11, 20263 min read
Ai Coding Tools

Why AI Coding Assistants Are Overrated for Beginners in 2026

Why AI Coding Assistants Are Overrated for Beginners in 2026 As a solo founder or indie hacker, it’s tempting to think that AI coding assistants are the silver bullet to jumpstart

Oct 10, 20263 min read
Ai Coding Tools

10 Common Mistakes When Using AI Coding Tools for Beginners

10 Common Mistakes When Using AI Coding Tools for Beginners As a beginner in coding, diving into AI coding tools can feel like a doubleedged sword. On one hand, these tools promise

Oct 8, 20264 min read