This is a very simple Node application with Express, created following the tutorial by James Hibbard on SitePoint.
Prior to following this tutorial I had never used Pug or Mongoose, so this was an opportunity to learn something new.
The tutorial has been followed to the letter, with the exception of the following:
- The Express server port is configurable via environment variable;
- The list of users registered appears also as a definition list;
- There is a link to view the list of registered users on the collection form;
- There is an additional route that shows the HTTP headers from the request;
- The Bootstrap source is referenced via CDN, not with a local inclusion;
- Node.js (the container)
- Express (the backend)
- MongoDB (the data persistence layer)
- Pug v3.0(the frontend template engine)
- Bootstrap v5.3.0 (the template styling)
- Clone the repository.
- Run
npm install
to install the dependencies. - Create a
.env
file in the project root calledPORT
andDATABASE
to store the port number of the server and the MongoDB connection string, respectively. - (optional) If running MongoDB locally, start the server with
mongod
.https://github.com/jameshibbard/demo-node-app - (optional) Modify the username and password in
users.htpasswd
file. - Run
npm run watch
to start the server and monitor for changes. - Visit http://localhost:PORT/ to see the application running.
- Visit http://localhost:PORT/registrations to see the list of submissions.
Note: the
/registrations
route is wrapped with a basic-auth middleware, so you will need to provide a username and password to access it. Overwrite the value you find inusers.htpasswd
with your own credentials, or useefabrizio
andpassword
as username and password, respectively.
While following the tutorial I found a few useful things:
- I liked the simple tool to generate a hashed passwd file.
- I discovered new ways to create templates with Pug, especially via the HTML-to-Pug Generator.
- I enjoyed learning to use the official MongoDB GUI tool, Compass.
Obviously this is totally free to use and distribute as you wish. All credit goes to SitePoint and James Hibbard for the tutorial idea, and the code I used to make this repository.