Serving static files in Express

 Serving static files in Express: Express allows you to serve static files, such as images, CSS files, and JavaScript files. You can use the express.static middleware to serve these files from a directory. Here's an example of how to serve static files in Express:

javascript


const express = require('express');

const app = express();


app.use(express.static('public'));


app.listen(3000, () => {

  console.log('Server listening on port 3000');

});

In this example, the public directory contains the static files that will be served by Express.

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...