can you use express.js as a full web server code example
Example 1: node js express
basic server
const express =require('express');
const app = express();
const PORT = 5000;
app.get('/',(req,res)=>{
res.json({message: 'Welcome to the backend'})
})
app.listen(PORT ,()=>console.log(`Connected to ${PORT}`)
Example 2: express and node
const http = require("http");
const hostname = "127.0.0.1";
const port = 8000;
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
})
Example 3: express js
Express.js, or simply Express, is a web application framework for Node.js,
released as free and open-source software under the MIT License.
It is designed for building web applications and APIs.
It has been called the de facto standard server framework for Node.js.