This README provides detailed instructions for setting up and using a full-stack application built with Node.js for the backend and React.js for the frontend. The application includes a RESTful API for managing 'Users' and 'Books' with a many-to-many relationship and a user interface for interacting with the API.
1. Initialize a Node.js project:
mkdir easylauncher_assignment
cd easylauncher_assignment
mkdir server
cd server
npm init -y
4. Install necessary npm packages:
npm install express sequelize pg pg-hstore bcryptjs jsonwebtoken cors dotenv
5. Edit the config/config.json file to configure your database credentials.
6. Create models for 'Users' and 'Books':
7. Create a join table for the many-to-many relationship:
8. Update the associations in your models (models/user.js models/book.js and models/userBook.js).
9. Create RESTful API routes in app.js or separate route files for 'Users' and 'Books'.
10. Implement JWT-based authentication in your user routes.
11. Secure your REST API by verifying the JWT in subsequent requests using middleware.
12. Set up a React.js application
cd ..
mkdir frontend
cd frontend
npx create-react-app library_management
14. Install necessary npm packages:
npm install axios react-router-dom
15. Develop the user interface components for managing users and books.
16. Implement forms for adding new users and books.
17. Create lists or tables to display existing users and books.
18. Implement authentication mechanisms using hooks or context to manage state and provide a secure way to authenticate API calls.
19. Implement JWT-based authentication on the backend by creating routes for user registration and login.
20. Upon successful authentication generate and return a JWT to the client.
21. Secure your REST API by creating middleware to verify the JWT on protected routes.
22. Start the backend server:
cd ..
cd backend
npm start
24. Start the frontend React application:
cd frontend
npm start
26. Access the application in your browser at http://localhost:3000.
27. Use the user interface to interact with the backend API and perform CRUD operations on users and books.
The backend of this application is built using Node.js and Express. Sequelize is used as an ORM to interact with the MySQL or PostgreSQL database. The database schema consists of two main entities: 'Users' and 'Books' with a many-to-many relationship managed through a join table. The frontend of this application is built using React.js. Axios is used to make API calls to the backend server. The user interface includes forms for adding new users and books as well as lists or tables to display existing entries. Authentication mechanisms are implemented on the frontend to ensure that API calls are authenticated. JWT-based authentication is implemented on the backend to handle user registrations and logins. Tokens are generated upon successful authentication and are used to secure subsequent requests to protected routes.
Technologies used in the project:
- Node.js
- React.js
- npm
- jwt