building an express server code example
Example 1: how to make an express server
const express = require('express');
const app = express();
app.get('/', (req,res)=>{
res.send('This is the home page!');
});
let PORT = 3000;
app.listen(PORT)
Example 2: simple express server
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;
app.get('/', (req, res) => {
res.send('<h1>Some HTML</h1>');
res.send('<p>Even more HTML</p>');
});
app.listen(PORT, () => console.log(`Server is listening on port ${PORT}`));
Example 3: js express server
const http = require('http')
const express = require('express')
const app = express()
const server = http.Server(app)
app.set('port', 8888)
server.listen(8888)
app.get('/', (req, res) => {
res.json({teste: true})
})