Skip to content

Commit

Permalink
update more code and Snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
Code-With-Abhishek-Kumar committed Oct 7, 2024
1 parent a92b3ef commit a7091e3
Show file tree
Hide file tree
Showing 47 changed files with 21,938 additions and 16 deletions.
176 changes: 173 additions & 3 deletions Express/02_Day_Express_Basic/Express_Basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,91 @@
- [=\> In This Syntax:](#-in-this-syntax)


## What is a Framework?



- A framework is a collection of pre-written code that provides a structure and tools for developers. It helps them build applications more easily by handling common tasks, so they can focus on creating the unique features of their software. This makes the development process faster and more organized.

- Framework ek pre-defined structure hota hai jo developers ko software applications banate waqt guidelines aur tools provide karta hai. Ye ek foundation ki tarah hota hai jisse aap apni application ke architecture ko design kar sakte hain. Frameworks generally common functionalities aur features ke saath aate hain, jisse developers ko basic tasks ko baar-baar likhne ki zaroorat nahi padti. Iska fayda ye hai ke aap apne kaam par focus kar sakte hain, jaise ki business logic aur user experience, bina infrastructure ke chinta kiye. Frameworks ka use karne se coding ka process faster aur organized hota hai, aur ye best practices ko follow karne mein bhi madad karte hain.


### Is a Framework Pre-Written Code?

Yes, a framework consists of pre-written code that provides a foundation for developers. It handles common tasks and helps developers build applications more easily, allowing them to concentrate on creating unique features.

## Benefits of Using a Framework

1. **Faster Development**: Since many common functionalities are pre-built, developers can complete projects more quickly.

2. **Organization**: Frameworks provide a structured way to organize code, making it easier to read and maintain.

3. **Best Practices**: They help ensure that developers follow best practices and industry standards, which can improve code quality.

4. **Community Support**: Popular frameworks often have large communities, meaning more resources, tutorials, and plugins are available.

## Examples of Frameworks

Here are some popular frameworks:

1. **Express.js**:
- A framework for building web applications using Node.js. It provides tools for setting up routes, handling requests, and managing middleware, making server-side application development easier.

2. **React**:
- A JavaScript library (often considered a framework) for building user interfaces. It helps developers create interactive and dynamic web pages by managing how components update and interact with each other.

3. **Django**:
- A web framework for Python. It includes built-in features for database management, user authentication, and URL routing, allowing developers to create complex web applications quickly.

4. **Ruby on Rails**:
- A framework for building web applications using the Ruby programming language. It emphasizes convention over configuration, providing sensible defaults to help developers get started faster.

5. **Angular**:
- A framework for building web applications using TypeScript. It provides tools for creating single-page applications, enabling a smooth user experience without full page reloads.

## Common Questions About Frameworks

1. **Why should I use a framework?**
- Using a framework can speed up development, ensure code quality, and provide helpful tools and libraries that simplify complex tasks.

2. **Are all frameworks the same?**
- No, different frameworks are designed for different purposes. For example, some are focused on web development (like Express.js), while others are for front-end interfaces (like React).

3. **Can I build applications without a framework?**
- Yes, but it may take longer and require more effort to manage common tasks that frameworks handle automatically.

4. **How do I choose the right framework?**
- Consider factors like the project requirements, community support, ease of use, and your familiarity with the programming language associated with the framework.



## What is NodeJs ?



- `NodeJs` hain Khoob Sara C++ Ka code jo ki Liya gaya hain Chrome browser ka V8 engine K code se aur is C++ Code Jisko liya gaya hain usey wrap kar diya gaya Js Code se or ye hame allow karta hain ke hum Js code likhein aur ye hame C++ k Basic par humlogo k liye server environment bana kar dega . par sirf tub tak jub tak node Chalu hain.

## What is Express ?

- ` Express.js ` ek powerful aur flexible web application framework hain jo Node.Js par based hain . Yeh Framework developers ko web application banane main madad karta hain server-side development ko simplify karta hain.

- Express ke through , hum routes define kar sakte hain jo URL Par incoming requests ko sahi jagah redirect karta hain . Iske alawa Express.js middleware ka use karke request aur response ke beech ka interaction manage karne main asan karta hain.
- Express.js is a lightweight web application framework for Node.js, designed to simplify the development of web applications and APIs. It provides a set of features for building web and mobile applications, allowing developers to create robust, scalable server-side applications efficiently.



- Express.js ek lightweight web application framework hai jo Node.js pe based hai. Ye web applications aur APIs ke development ko aasan banane ke liye design kiya gaya hai. Is framework ka main aim hai ki developers ko powerful server-side applications jaldi aur efficiently banane ki suvidha di jaye. Express web aur mobile applications banane ke liye features ka ek set provide karta hai, jisse developers mazboot aur scalable applications easily create kar sakte hain.

- Express ke through, hum routes define kar sakte hain jo URL par incoming requests ko sahi jagah redirect karte hain. Ye routing capabilities kaafi flexible hain; aap alag-alag HTTP methods (GET, POST, PUT, DELETE) aur URL paths ko manage kar sakte hain. Iska matlab hai ki jab koi user aapki website par specific URL visit karta hai, aap us URL ke liye specific functionality execute kar sakte hain.

- Express.js middleware ka use karke request aur response ke beech ka interaction manage karna asan hota hai. Middleware functions ko aap incoming requests par operations perform karne ke liye use kar sakte hain, jese logging (requests ka record rakhna), user authentication (ye check karna ki user valid hai ya nahi), aur error handling (agar koi problem aaye toh usse manage karna). Ye middleware code ko reusability aur modularity ka mauka deta hai, matlab aap ek baar likha hua code baar-baar use kar sakte hain.

- Iske alawa, Express mukhtalif template engines ko support karta hai, jaise Pug ya EJS, jo dynamic HTML pages generate karne mein madad karte hain. Iska matlab hai ki aapke web pages user input ya database se aaye data ke aadhar par badalte hain, jo user experience ko enhance karta hai. Express ko TJ Holowaychuk ne 2010 mein banaya tha, unhone is framework ko aasan aur efficient web application development ke liye design kiya tha.

- Express ki simplicity aur flexibility ki wajah se, ye rapidly grow hua hai aur ek badi community of users aur contributors bana chuka hai jo iski improvement aur features ko enhance karne mein kaam karte hain. Is framework ke mukhya objectives mein complexity ko kam karna, middleware support dena, robust routing capabilities provide karna, aur performance ko enhance karna shamil hai. Express high-performance applications ke liye perfect hai kyunki ye bohot saari simultaneous connections ko efficiently handle kar sakta hai, jisse aapki application fast aur reliable hoti hai.



## What is Npm ?


- `NPM ` pehle `Node package Manager` ke roop mein jaana jaata tha lekin ab iska koi official name nhi hain yeh generally NPM ke roop mein hi jaana jaata hain.

- Ye Pehle `Node.js ke package ko manage karne ke liye banaya gaya tha` lekin samay ke saath iska scope badh gaya hain . Ab Npm JavaScript Ecomsystem ke har type ke package aur liberies ko manage karta hain.
Expand All @@ -33,6 +103,106 @@
- Isse fronted developer ho ya Server-Side programming dono ko various development environment mein flexibility milti hain.




# Understanding package.json and npm

## What is package.json?

`package.json` ek khaas JSON file hai jo Node.js projects mein istemal hoti hai. Ye file kai important kaamon ke liye madadgar hoti hai:

`package.json` is a special JSON file used in Node.js projects that serves several important purposes:

1. **Project Information**:
- Ye file aapke project ki zaroori details rakhti hai, jaise:
- This file contains essential details about your project, such as:
- **Project Name**: Aapke project ka naam.
- **Version**: Aapke project ki current version (jaise 1.0.0).
- **Description**: Ek chhoti si line jo batati hai aapka project kya karta hai.
- **Author**: Wo vyakti ya team jinhone project banaya.
- **License**: Ye batata hai ki dusre is project ko kaise use kar sakte hain.
- **Keywords**: Aise shabd jo aapke project ko dhoondhne mein madad karte hain.

2. **Dependencies**:
- Ye section un libraries ya tools ko list karta hai jo aapke project ko chalane ke liye zaroori hain.
- This section lists the libraries or tools that are necessary for your project to run.
- Jaise: `"express": "^4.17.1"` ka matlab hai ki aapka project Express library ko chahiye, aur ye 4.17.1 se lekar 5.0.0 tak koi bhi version use kar sakta hai.
- For example: `"express": "^4.17.1"` means your project needs the Express library, and it can use any version from 4.17.1 up to, but not including, 5.0.0.

3. **Scripts**:
- Aap yahan commands set kar sakte hain jo tasks automate karne mein madad karte hain.
- You can define commands here that help automate tasks.
- Jaise: `"start": "node index.js"` aapko `npm start` likhkar application chalane deta hai.
- For example: `"start": "node index.js"` lets you run your app using `npm start`.

4. **Configuration**:
- Ye file project aur uski libraries ke liye settings rakhti hai.
- This file holds configuration settings for the project and its libraries.

### Key Parts Explained

- **name**: Aapke project ka unique naam. Isay simple aur lowercase rakhein.

**name**: The unique name of your project. Keep it simple and in lowercase.

- **version**: Ye project ki version dikhata hai, format hota hai MAJOR.MINOR.PATCH.
- Example: `1.0.0` pehla stable version hai.

**version**: This shows the version of your project, formatted as MAJOR.MINOR.PATCH.
- Example: `1.0.0` is the first stable version.

- **description**: Chhoti summary jo batati hai aapka project kya karta hai.

**description**: A short summary that tells what your project does.

- **main**: Wo main file jo run hoti hai jab aapka project start hota hai (jaise `index.js`).

**main**: The main file that runs when your project starts (like `index.js`).

- **scripts**: Commands jo aap terminal mein chala sakte hain.

**scripts**: Commands that you can run in the terminal.

- **author**: Aapka naam ya organization ka naam jo project maintain karti hai.

**author**: Your name or the name of the organization maintaining the project.

- **license**: Project ke liye use hone wala license (jaise MIT).

**license**: The license under which the project is used (like MIT).

- **dependencies**: Un libraries ki list jo aapke project ko chalane ke liye zaroori hain.

**dependencies**: A list of libraries that are necessary for your project to run.

### Example of package.json

Yahan ek basic example diya gaya hai jo dikhata hai `package.json` file kaise hoti hai:

Here’s a simple example showing how a `package.json` file looks:

```json
{
"name": "my-express-app",
"version": "1.0.0",
"description": "A simple Express.js application",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
},
"author": "Your Name",
"license": "MIT",
"dependencies": {
"express": "^4.17.1"
}
}




<!-- -->

### Npm install

```console
Expand Down
112 changes: 110 additions & 2 deletions Express/06_Day_Basic routing/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,119 @@

## What is Routing

- Routing in Express.js meance deciding how Our Web Application should respond When it gets a request at difference website address(URLs) it's like giving direction to the app on What to do When Someone visits a specific page.
### English:
Routing in Express refers to how an application’s endpoints (URIs) respond when they receive requests from clients. It allows you to define the paths users can access in your application and determine how your server should respond to different HTTP requests, such as GET, POST, PUT, and DELETE. By setting up routes, you can manage different actions for different requests—like retrieving data, submitting forms, updating information, or deleting resources. Additionally, routing helps organize your code by separating the logic for different parts of your application, making it easier to maintain and understand. Overall, routing is essential for building interactive web applications where users can navigate between different pages and functionalities smoothly.

### Hinglish:
Express mein routing ka matlab hai ki ek application ke endpoints (URIs) client requests par kaise respond karte hain jab unhe requests milti hain. Yeh aapko yeh define karne ki suvidha deta hai ki users aapke application mein kaunse paths ko access kar sakte hain aur aapka server alag-alag HTTP requests, jaise GET, POST, PUT, aur DELETE par kaise respond karega. Routes set karne se aap alag-alag requests ke liye alag actions manage kar sakte hain—jaise data ko retrieve karna, forms ko submit karna, information update karna, ya resources ko delete karna. Iske alawa, routing aapke code ko organize karne mein madad karta hai, alag-alag parts ke liye logic ko separate karke, jis se aapka code maintain karna aur samajhna aasan ho jata hai. Overall, routing web applications banane ke liye zaroori hai jahan users alag-alag pages aur functionalities ke beech smoothly navigate kar sakte hain.


```javascript
app.METHOD(PATH, HANDLER)
```

### How to Define Routes?

In Express.js, routes are defined using methods associated with HTTP methods. Each method corresponds to a different type of request that can be made by the client.

#### 1. `app.get()`

**Usage:**
Handles GET requests, which are typically used to retrieve data from the server.

**When to Use:**
- When you want to fetch resources, such as retrieving a list of users or fetching a specific item from a database.

**Example:**
```javascript
app.get('/users', (req, res) => {
// Code to fetch and return users
});

```

#### 2. `app.post()`

**Usage:**
Handles POST requests, which are generally used to submit data to the server, such as creating a new resource.

**When to Use:**
- When you want to create a new resource, like adding a new user or submitting a form.

**Example:**
```javascript
app.post('/users', (req, res) => {
// Code to create a new user
});

```


#### 3. `app.put()`

**Usage:**
Handles PUT requests, typically used to update existing resources.

**When to Use:**
- When you want to update a specific resource, such as modifying a user's details.

**Example:**
```javascript
app.put('/users/:id', (req, res) => {
// Code to update user with the given ID
});

```
#### 4. `app.delete()`

**Usage:**
Handles DELETE requests, used to delete a specified resource.

**When to Use:**
- When you want to remove a resource from the server, like deleting a user.

**Example:**
```javascript
app.delete('/users/:id', (req, res) => {
// Code to delete user with the given ID
});

```

#### 5. `app.all()`

**Usage:**
Handles all HTTP methods for a specific route.

**When to Use:**
- When you want to apply the same logic to different HTTP methods for a particular route, or for middleware functions.

**Example:**
```javascript
app.all('/users', (req, res) => {
// Code to handle requests regardless of the HTTP method
});
```


#### 6. `app.use()`

**Usage:**
Used to define middleware, which are functions that execute during the request-response cycle.

**When to Use:**
- When you want to run code for every request, such as logging, authentication, or parsing request bodies.

**Example:**
```javascript
app.use((req, res, next) => {
console.log('Request received:', req.method, req.url);
next(); // Pass control to the next middleware
});
```



### Example of Routingg

- Sochiya aapko Web application hain aur aap 'Contact Us' Page ko handle karna chahte ho. Toh aap Express mein routes define kar sakte hain.
Expand Down Expand Up @@ -165,4 +273,4 @@ app.listen(3000, () => {
``` -->
``` -->
File renamed without changes.
1 change: 1 addition & 0 deletions Express/NodeJs_Backend_Production_Setup/StarterCode
Submodule StarterCode added at c11176
60 changes: 60 additions & 0 deletions Express/NodeJs_Backend_Production_Setup/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
1. Download node js

2. npm init


3. pkg.json


4. npm i husky lint-staged -D

5. npx husky init

6. Add this line inside Your package.json
````bash
"scripts": {
"test": "node test.js",
"prepare": "husky"
},

````

6. create a file test.js


7. Setup TypeScript

```bash
npm i typescript -D

```
8. init TypeScript

```bash
npx tsc --init

```

9.


```bash
npm i -D @types/node

```
10

```bash
npm i -D nodemon

```

11.

```bash
npm i -D ts-node

```



Loading

0 comments on commit a7091e3

Please sign in to comment.