This backend powers the Moddie View application, handling real-time synchronization via WebSockets, interacting with the YouTube API for video search, and managing room states.
- Node.js & Express: For the core server and REST API.
- Socket.io: For real-time bidirectional event-based communication.
- TypeScript: For static typing and better developer experience.
- Redis: For caching and state management.
Before running the project, ensure you have the following installed:
The project uses .env files located in the config directory. To run the project locally, modify config/.env.development with the required variables. Here is an example of what it looks like:
## Environment ##
NODE_ENV=development
## Server ##
PORT=3000
HOST=localhost
## Setup jet-logger ##
JET_LOGGER_MODE=console
JET_LOGGER_FILEPATH=jet-logger.log
JET_LOGGER_TIMESTAMP=true
JET_LOGGER_FORMAT=line
## Redis ##
REDIS_HOST=localhost
REDIS_PORT=6379
# REDIS_USERNAME=default
# REDIS_PASSWORD=
## External APIs ##
YOUTUBE_API_KEY=your_youtube_api_key_here
## Security / Auth ##
JWT_SECRET=your_jwt_secret_hereFollow these steps to get the backend up and running locally.
npm install(Or use npm run clean-install for a fresh installation)
Navigate to the config folder and ensure .env.development is set up correctly with your database credentials and API keys.
Make sure that your Redis and PostgreSQL instances are running and accessible on the ports specified in your .env.development file.
Development Mode: To run the server with hot-reloading for development:
npm run dev:watchProduction Mode: To build and run the server in a production-like environment:
npm run build
npm startnpm run dev: Runs the application in development mode usingts-node.npm run dev:watch: Runs the application in development mode usingnodemonfor auto-restarts on file changes.npm run build: Lints the code and compiles TypeScript to JavaScript in thedistfolder.npm start: Runs the compiled application in production mode.npm run lint: Runs ESLint on the project.npm run format: Formats the code using Prettier.npm test: Runs the test suite using Vitest.npm run clean-install: Removesnode_modulesandpackage-lock.json, then performs a fresh install.
The backend exposes an Express API and a Socket.io server.
GET /api/youtube/search: Searches for YouTube videos (requiresYOUTUBE_API_KEY).POST /api/room: Creates a new room and returns the room details.
- The WebSocket server runs on the same port as the HTTP server.
- Used to handle room state, synchronize media playback, and process real-time events between users in a room.
