I am reading the book, Pro Angular.js and practicing the samples on the book. However, many samples have been already deprecated. The static file server using connect.js is as well. Furthermore, the hapi file server that I implemented has been deprecated too. Therefore, I had to find the alternatives.
serve-static in expressjs
Make a project folder
npm initto initialize the node project.
Install finalhandler and serve-static npms.
npm init; npm install —save-dev final handler serve-static
Make a file - server.js - in the project root folder.
Add the following contents to the server.js file. The file path with the serveStatic function should be changed for your file path.
- Let’s run the file server.
- Test with
localhost:3000/filenameon a Web browser.