Skip to content

Instantly share code, notes, and snippets.

@kom50
Created December 8, 2022 15:39
Show Gist options
  • Save kom50/d8ba5f3b60cdd622d5df8e23b8c41604 to your computer and use it in GitHub Desktop.
Save kom50/d8ba5f3b60cdd622d5df8e23b8c41604 to your computer and use it in GitHub Desktop.
How to create server in express JS
import express, { Express, Request, Response } from 'express';
import dotenv from 'dotenv';
import bodyParser from 'body-parser';
dotenv.config();
const app: Express = express();
const PORT = process.env.PORT || 5000;
app.use(express.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ extended: true, limit: '50mb' }))
app.get('/', (req: Request, res: Response) => {
res.send('<h1>Express + TypeScript Server</h1>');
});
app.listen(PORT, () => {
console.log(`🚀 Server is running at https://localhost:${PORT}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment