- Node.js and npm installed on your machine.
- MongoDB installed and running on your local machine.
-
Navigate to the
backend
folder:cd my-website/backend
-
Install the necessary dependencies:
npm install
-
Start the backend server:
npm start
The server will run on
http://localhost:3000
.
- No additional setup is required for the frontend. Just open the
index.html
file in your browser or serve it using a static file server.
-
Make sure MongoDB is running on your machine.
-
Start the backend server as described above.
-
Open
frontend/index.html
in your browser. You should see the homepage of the website.
-
Register a New User:
- Navigate to the register page (
register.html
). - Fill in the username and password fields and submit the form.
- You should see a success message indicating that the user has been registered.
- Navigate to the register page (
-
Login:
- Navigate to the login page (
login.html
). - Enter the registered username and password and submit the form.
- On successful login, you will be redirected to the dashboard page.
- Navigate to the login page (
-
Dashboard:
- The dashboard page (
dashboard.html
) will display a welcome message with the logged-in username. - You can log out using the logout button.
- The dashboard page (
- The JWT token is stored in the browser's local storage for authentication.
- The token expires after 1 hour.
- The backend server uses Express for routing and Mongoose for MongoDB interactions.
- Passwords are hashed using bcryptjs before storing in the database.
- JWT (JSON Web Token) is used for user authentication.
Feel free to modify and enhance the project according to your needs.
This project is licensed under the MIT License.