Node.JS Static Server


https://www.npmjs.com/package/node-static


$ npm init -y
$ npm install --save node-static


$ mkdir -p public
$ vi ./public/index.html


<!DOCTYPE html>
<html>
  <head>
    <title>Test</title>
    <meta charset="UTF-8" />
  </head>
  <body>
    <h1>WTF!</h1>
  </body>
</html>


$ vi server.js


var static = require('node-static');

const port = 8080;

const file = new static.Server('./public');

require('http')
  .createServer(function (request, response) {
    request
      .addListener('end', function () {
        file.serve(request, response);
      })
      .resume();
  })
  .listen(port, function () {
    console.log('Server started on port ' + port);
  });


$ node server.js


http://localhost:8080


Node.JS Static Server (with React app)

https://bitbucket.org/marley-react/The-Complete-React-Web-App-Developer-Course