You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generate .env file inside your root project folder and put the next code
PORT=8000
Create your file server
Create index.ts file at your folder root project
import express, { Express, Request, Response } from 'express';
import dotenv from 'dotenv';
import cors from 'cors';
// Load environment variables from .env file, where API keys and passwords are configured
dotenv.config();
// Create Express server
const app: Express = express();
// Express third party middleware for handling CORS
app.use(cors());
// Define port to the Express server will be running on
const port = process.env.PORT;
// Express test route for checking if everything is working
app.get('/', (req: Request, res: Response) => {
res.send('Express + TypeScript Server');
});
// Start Express server
app.listen(port, () => {
console.log(
`[server]: Server is running at http://localhost:${port}`
);
});