This project demonstrates a web application built with Node.js, Express, Sequelize, and HTMX, containerized using Docker. It includes a user registration form that stores user data in a PostgreSQL database.
- Node.js: A JavaScript runtime for server-side development.
- Express: A web application framework for Node.js.
- Sequelize: An Object-Relational Mapping (ORM) library for Node.js, supporting various databases including PostgreSQL.
- HTMX: A library that allows you to add interactivity to your web pages using HTML attributes.
- PostgreSQL: A powerful, open-source relational database system.
- Docker: A platform for developing, shipping, and running applications using containers.
- Passport: Authentication middleware for Node.js.
Before running this project, ensure that you have the following installed on your system:
- Node.js: Install Node.js
- Docker: Install Docker
- Docker Compose: Install Docker Compose
-
Clone the repository:
https://github.com/Gords/NodePSD-Base.git
-
Navigate to the project directory:
cd NodePSD-Base
-
Build and start the Docker containers:
docker-compose up --build
This command will build the Docker images and start the containers defined in the
docker-compose.yml
file. -
Access the application in your web browser at
http://localhost:3000
.You should see the user registration form rendered by the HTMX page.
-
Fill in the form with an email, password, and name, and click the "Register" button.
The form data will be submitted to the server using HTMX, and the server will process the request, insert the user data into the database, and send a response back to the client.
-
To stop the containers, press
Ctrl + C
in the terminal where the containers are running.Alternatively, you can run the following command in a separate terminal window:
docker-compose down
This command will stop and remove the containers.
To additionally remove the volumes you can run:
docker-compose down -v
The project structure is as follows:
NodePSD-Base/
├── public/
│ └── index.html
├── migrations/
│ └── ...
├── models/
│ └── ...
├── config/
│ └── config.js
├── .env
├── .gitignore
├── .sequelizerc
├── Dockerfile
├── app.js
├── docker-compose.yml
├── package.json
└── package-lock.json
public/
: Contains the static files served by the application, including theindex.html
file with the user registration form.migrations/
: Contains the database migration files generated by Sequelize.models/
: Contains the Sequelize model definitions, including theUser
model.config/
: Contains the configuration files, including the database configuration inconfig.js
..env
: The environment file that stores sensitive configuration variables..gitignore
: Specifies the files and directories that should be ignored by Git..sequelizerc
: The configuration file for Sequelize CLI.Dockerfile
: The Dockerfile that defines the application's container environment.app.js
: The main application file that sets up the Express server and defines the routes.docker-compose.yml
: The Docker Compose file that defines the services and their configurations.package.json
andpackage-lock.json
: The files that manage the project's dependencies.
The project uses Sequelize migrations to manage database schema changes. To create a new migration, run the following command:
npx sequelize-cli migration:generate --name migration-name
Replace migration-name
with a descriptive name for your migration
To run the pending migrations and update the database schema, use the following command:
npm run db:migrate