How to do it...

  1. Create a new directory named public
  2. Move into the new public directory
  3. Create a new file named index.html
  4. Add the following code:
      <!DOCTYPE html> 
      <html lang="en"> 
      <head> 
          <meta charset="utf-8"> 
          <title>Simple Web Application</title> 
      </head> 
      <body> 
          <section role="application"> 
        <h1>Welcome Home!</h1> 
          </section> 
      </body> 
      </html> 
  1. Save the file
  2. Navigate back out of the public directory
  3. Create a new file named serve-static-assets.js
  1. Add the following code. Initialize a new ExpressJS application:
      const express = require('express') 
      const path = require('path') 
      const app = express() 
  1. Include the express.static configurable middleware function and Pass the path of the /public directory where index.html file is located:
      const publicDir = path.join(__dirname, './public') 
      app.use('/', express.static(publicDir)) 
  1. Listen on port 1337 for new connections:
      app.listen( 
          1337, 
          () => console.log('Web Server running on port 1337'), 
      ) 
  1. Save the file
  2. Open a terminal and run:
      node serve-static-assets.js
  1. To see the result, in your browser, navigate to:
      http://localhost:1337/index.html
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.25.231