1//to run : node filename.js
2const express = require('express')
3const app = express()
4const port = 3000
5
6app.get('/', (req, res) => res.send('Hello World!'))
7
8app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))
9
10//visit localhost:3000
11// assuming you have done 1) npm init 2) npm install express
1const express = require('express');
2const app = express();
3const PORT = process.env.PORT || 3000;
4
5app.get('/', (req, res) => {
6 res.send('<h1>Some HTML</h1>');
7 res.send('<p>Even more HTML</p>');
8});
9
10app.listen(PORT, () => console.log(`Server is listening on port ${PORT}`));
1const express = require('express')
2const app = express()
3const port = 3000
4
5app.get('/', (req, res) => res.send('Hello World!'))
6
7app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))
1basic server
2
3const express =require('express');
4const app = express();
5const PORT = 5000;
6
7
8app.get('/',(req,res)=>{
9 res.json({message: 'Welcome to the backend'})
10})
11
12
13app.listen(PORT ,()=>console.log(`Connected to ${PORT}`)
14
15