{"id":25062816,"url":"https://github.com/sougata-github/backend-course","last_synced_at":"2025-10-30T22:36:18.980Z","repository":{"id":273311635,"uuid":"919271107","full_name":"sougata-github/backend-course","owner":"sougata-github","description":"Backend course","archived":false,"fork":false,"pushed_at":"2025-02-22T14:07:33.000Z","size":184,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-22T15:20:09.924Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sougata-github.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-20T04:49:34.000Z","updated_at":"2025-02-22T14:07:36.000Z","dependencies_parsed_at":"2025-01-20T06:33:30.377Z","dependency_job_id":"fd474194-e8f7-41dd-b498-777cd9ef6234","html_url":"https://github.com/sougata-github/backend-course","commit_stats":null,"previous_names":["sougata-github/backend-course"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sougata-github%2Fbackend-course","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sougata-github%2Fbackend-course/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sougata-github%2Fbackend-course/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sougata-github%2Fbackend-course/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sougata-github","download_url":"https://codeload.github.com/sougata-github/backend-course/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246460871,"owners_count":20781220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-06T17:13:31.948Z","updated_at":"2025-10-30T22:36:13.947Z","avatar_url":"https://github.com/sougata-github.png","language":"CSS","readme":"## Backend\n\nFull-stack development encompasses the entire web experience, from typing in a URL to interacting with a webpage.\n\nIt primarily consists of two parts:\n\n- **Frontend**\n- **Backend**\n\nThe **Frontend** is what we see and interact with when we visit a website. It includes the user (us) and the client (browser). The client is the medium through which we access and interact with the internet.\n\n### What happens when we type in a URL?\n\n- The browser sends out a **network request**.\n\n- This request is directed to an address to locate a server (another device) with a specific **IP address** connected to the internet.\n\n- The **URL** (Uniform Resource Locator) is a human-readable address. It is translated into a numerical IP address by the **DNS (Domain Name System)**. For example, the domain `youtube.com` is converted into a series of numbers (`142.250.190.46`).\n\n- The server listens for incoming requests on specific ports. Once the server receives the request, it processes any incoming data and prepares a response, which may involve fetching data from a database or performing some computations.\n\n- The server responds to the browser with the requested data, often in the form of **HTML, CSS, and JavaScript** files, or API responses in formats like **JSON**.\n\n- The browser receives the response, parses the **HTML**, and uses additional resources (CSS, JavaScript) to render and display the webpage to the user.\n\n### Backend Development with JavaScript\n\n#### Setting Up the Environment\n\nWe utilize **npm** (Node Package Manager) for managing packages in our backend projects.\n\n- Check Node.js and npm Installation\n\nTo verify that Node.js and npm are installed on your system, run the following commands in your terminal:\n\n```bash\nnode -v\nnpm -v\n```\n\nThese commands display the installed versions of Node.js and npm. If they are not installed, download and install them from Node.js official website.\n\n- Initialize the Project\n\nTo set up a new Node.js project, use the following command:\n\n```bash\nnpm init -y\n```\n\nThe above command initialises node.js backend project. It creates a package.json file which serves as a blueprint for your project, specifying its metadata and dependencies.\n\n#### Building Server-Side Applications with Node.js and Express.js\n\nWhen creating server-side applications with Node.js, a widely used framework is `Express.js`\n\n- Adding Dependencies\n\nThe `dependencies` section in the `package.json` file lists all the packages your project relies on. Adding Express.js as a dependency ensures that anyone downloading your project can install the required packages using `npm install`\n\n- To install Express.js, run:\n\n```bash\nnpm install express\n```\n\nAll installed packages are stored in the `node_modules` folder.\n\nUse scripts to get your server up and running (for example: \"dev\") and then we can tell `npm` to run that script. In this case `npm run dev`\n\nTo restart our server automatically on changes, use `nodemon` (dev dependency)\n\nThe `public` directory in a project is where static assets like HTML files, images, and other resources are served directly to the client without processing.\n\n#### Node.js + Express + TypeScript Setup Guide\n\nProject setup\n\n- TypeScript Configuration (`tsconfig.json`)\n\n```json\n{\n  \"compilerOptions\": {\n    \"target\": \"es2016\",\n    \"module\": \"nodenext\",\n    \"moduleResolution\": \"nodenext\",\n    \"resolveJsonModule\": true,\n    \"outDir\": \"./dist\",\n    \"esModuleInterop\": true,\n    \"forceConsistentCasingInFileNames\": true,\n    \"strict\": true,\n    \"skipLibCheck\": true\n  },\n  \"include\": [\"src/**/*\"]\n}\n```\n\nDepending on how you configure `package.json`, you must adjust import statements accordingly.\n\n- Default (CommonJS-like Behavior)\n\n  - package.json (No \"type\": \"module\" specified)\n  - Import style\n    ```typescript\n    import authRoutes from \"./routes/authRoutes\";\n    ```\n  - Dev Command\n    ```bash\n    nodemon --exec ts-node src/index.ts\n    ```\n\nWhen using `__dirname` and `__filename`\n\n- To use\n\n  ```typescript\n  import path from \"path\";\n  import { fileURLToPath } from \"url\";\n\n  const __filename = fileURLToPath(import.meta.url);\n  const __dirname = path.dirname(__filename);\n  ```\n\n- Add \"type\": \"module\" `in package.json`\n\n- Update imports to include file extensions, like:\n\n  ```typescript\n  import authRoutes from \"./routes/authRoutes.js\";\n  ```\n\n- Change the dev command to:\n\n  ```bash\n  npx tsx --watch src/index.ts\n  ```\n\nMigrations are used for version control of a database, they are essentially records of all the modifications made to a db and when you run these migrations, every instance of your db gets updated to reflect these changes. Keeps your db schema in sync with your prisma schema.\n\nDocker is used to containerize application and create a set of instructions for this container (virtual environment) that can be consistently across all systems.\n\nThe Docker file is an instruction sheet on how we can create an environment so that it has everything it needs to run our project.\n\nWe would also require a config sheet to boot up all these docker environments -\u003e `docker-compose.yaml` file\n\n#### Backend Docker Setup Guide\n\nThis guide will walk you through setting up the **backend Todo app** using **Docker, PostgreSQL, and Prisma**.\n\n---\n\n- Install Docker\n\nMake sure you have **Docker Desktop** installed before proceeding.\n\n- [Download Docker Desktop](https://www.docker.com/products/docker-desktop/)\n\n---\n\n- Clone the Repository\n\n```bash\ngit clone https://github.com/your-username/backend-todo-app.git\ncd backend-todo-app\n```\n\n- Generate the Prisma Client\n\n```bash\nnpx prisma generate\n```\n\n- Build Docker Images\n\n```bash\ndocker compose build\n```\n\n- Create and Apply PostgreSQL Migrations\n\n```bash\ndocker compose run app npx prisma migrate dev --name init\n```\n\n- If migrations need to be applied later\n\n```bash\ndocker compose run app npx prisma migrate deploy\n```\n\nBoot Up Docker Containers\n\n- To start the application with 2 containers\n\n```bash\ndocker compose up\n```\n\n- To run it in the background\n\n```bash\ndocker compose up -d\n```\n\nRunning in detached mode (-d) means it won’t lock your terminal. You’ll need to stop it via Docker Desktop or `docker compose down`.\n\nAccess the PostgreSQL Database\n\n- While containers are running, open a new terminal and run\n\n```bash\ndocker exec -it postgres-db psql -U postgres -d my-app\n```\n\nThis lets you interact with the database using SQL commands.\n\nStopping Docker Containers\n\n```bash\ndocker compose down\n```\n\nDelete All Docker Containers\n\n```bash\ndocker system prune\n```\n\nOnce everything is running, open:\n`http://localhost:8000` (or `localhost:3000` if changed)\n\nYou can register, log in, and manage your app from there.\n\n#### Docker commands:\n\nContainer Management\n\n- List running containers\n\n```bash\ndocker ps\n```\n\n- List all containers\n\n```bash\ndocker ps -a\n```\n\n- Stop a runnning container\n\n```bash\ndocker stop \u003ccontainer_id\u003e\n```\n\n- Start a stopped container\n\n```bash\ndocker start \u003ccontainer_id\u003e\n```\n\n- Restart a container\n\n```bash\ndocker restart \u003ccontainer_id\u003e\n```\n\n- Remove a container\n\n```bash\ndocker rm \u003ccontainer_id\u003e\n```\n\nImage Management\n\n- List all downloaded images\n\n```bash\ndocker images\n```\n\n- Remove an image\n\n```bash\ndocker rmi \u003cimage_id\u003e\n```\n\n- Download an image from Docker Hub\n\n```bash\ndocker pull \u003cimage_name\u003e\n```\n\n- Build an image from a Dockerfile\n\n```bash\ndocker build -t \u003cimage_name\u003e\n```\n\nDocker Compose\n\n- Start all services in `docker-compose.yaml`\n\n```bash\ndocker compose up\n```\n\n- Rebuild images before starting services\n\n```bash\ndocker compose up --build\n```\n\n- Start services in detached mode (background)\n\n```bash\ndocker compose up -d\n```\n\n- Stop and remove all containers\n\n```bash\ndocker compose down\n```\n\n- View real-time logs of all services\n\n```bash\ndocker compose logs -f\n```\n\nVolumes \u0026 Networks\n\n- List all volumes\n\n```bash\ndocker volume ls\n```\n\n- Remove a volume\n\n```bash\ndocker volume rm \u003cvolume_name\u003e\n```\n\n- List all networks\n\n```bash\ndocker network ls\n```\n\n- Remove a network\n\n```bash\ndocker network rm \u003cnetwork_name\u003e\n```\n\nInstall \u0026 Debug\n\n- View logs od a container\n\n```bash\ndocker logs \u003ccontainer_id\u003e\n```\n\n- Open a shell inside a running container\n\n```bash\ndocker exec -it \u003ccontainer_id\u003e sh\n```\n\n- Get detailed info about a container\n\n```bash\ndocker inspect \u003ccontainer_id\u003e\n```\n\n- Show resource usage of running containers\n\n```bash\ndocker stats\n```\n\nCleanup\n\n- Remove unused container, images, and networks\n\n```bash\ndocker system prune\n```\n\n- Remove unused volumes\n\n```bash\ndocker volume prune\n```\n\n- Remove unused networks\n\n```bash\ndocker network prune\n```\n\n- Remove unused images\n\n```bash\ndocker image prune\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsougata-github%2Fbackend-course","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsougata-github%2Fbackend-course","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsougata-github%2Fbackend-course/lists"}