Express Build your first API endpoint with Express

This lesson is available for PRO members or as a single course purchase. Sign-in and choose a plan below.
Get Unlimited PRO Access

OR


*Enrollment provides full access to this course (and updates) for life.

Create an Express App

file_type_typescript api.ts
import express, { Request, Response } from 'express';
export const app = express();

// Allows cross origin requests
import cors from 'cors';
app.use(cors({ origin: true }));


app.use(express.json());


app.post('/test', (req: Request, res: Response) => {
  const amount = req.body.amount;
  res.status(200).send({ with_tax: amount * 7 });
});

Listen to Incoming Requests

file_type_typescript index.ts
// Start the API with Express
import { app } from './api';
const port = process.env.PORT || 3333;
app.listen(port, () => console.log(`API available on http://localhost:${port}`));

Questions?

Ask questions via GitHub below OR chat on Slack #questions