Skip to content

Commit

Permalink
Merge pull request #57 from Lavavarshney/main
Browse files Browse the repository at this point in the history
FEAT: Added  snippet for setting up express server, updated  README.md and snippet dependencies
  • Loading branch information
PranavBarthwal authored Nov 1, 2024
2 parents ec46c69 + 9195932 commit 7180508
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
49 changes: 20 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,34 @@ run generate-snippet multer-file-upload
This command will create a new file `multer-file-upload.js` in the current working directory, containing a pre-configured snippet for handling file uploads using `multer`.

### Available Snippets

1. **`async-ops-handler`**:
1. **`express-server`**:
Sets up express server.

**Code Snippet**:
```js
import express from "express";
const app = express();
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Server started at ${PORT}`));
```

2. **`async-ops-handler`**:
Handles asynchronous operations with error handling.

**Code Snippet**:

```js
const asyncHandler = (requestHandler) => {
return (req, res, next) => {
Promise.resolve(requestHandler(req, res, next)).catch((err) => next(err));
};
};

export { asyncHandler };
```

2. **`custom-api-error`**:
3. **`custom-api-error`**:
Standardizes error responses for your API.

**Code Snippet**:

```js
class ApiError extends Error {
constructor(statusCode, message = 'Something went wrong', errors = [], stack = '') {
Expand All @@ -134,7 +141,7 @@ This command will create a new file `multer-file-upload.js` in the current worki
export { ApiError };
```

3. **`custom-api-response`**:
4. **`custom-api-response`**:
Standardizes successful API responses.

**Code Snippet**:
Expand All @@ -152,7 +159,7 @@ This command will create a new file `multer-file-upload.js` in the current worki
export { ApiResponse };
```

4. **`multer-file-upload`**:
5. **`multer-file-upload`**:
Sets up a file upload service using `multer`.

**Code Snippet**:
Expand All @@ -170,9 +177,9 @@ This command will create a new file `multer-file-upload.js` in the current worki
});
export const upload = multer({ storage });
```
5. **`mongoose-con`**:
```
6. **`mongoose-con`**:
Sets up a connection to your mongodb using `mongoose`.

**Code Snippet**:
Expand All @@ -191,9 +198,10 @@ This command will create a new file `multer-file-upload.js` in the current worki
});
}
export default connectToDB;
```
6. **`mongoose-schema`**:
```
7. **`mongoose-schema`**:
Sets up a basic schema for your db using `mongoose`.

**Code Snippet**:
Expand All @@ -210,23 +218,6 @@ This command will create a new file `multer-file-upload.js` in the current worki
export default model;
```

7. **`rate-limit-middleware`**:
Sets up a rate limit middleware using `express-rate-limit`.

**Code Snippet**:

```js
import rateLimit from 'express-rate-limit';
const limiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 1000,
message: 'Too many requests from this IP, please try again after 15 minutes.',
});
export default limiter;
```

8. **`nodemailer`**:
Sets up email functionality in Node.js projects

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import chalk from 'chalk';
import ora from 'ora'; // Import the ora package
import inquirer from 'inquirer'; // Import the inquirer package
import { exec } from 'child_process'
import { generateGitignore } from './gitignoreGenerator.js';

import { dependencies } from './snippetdependencies.js';


Expand Down
4 changes: 3 additions & 1 deletion snippetdependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const dependencies = {
"mongoose-schema" : ['mongoose'],
"multer-file-upload" : ['multer'] ,
"nodemailer": ['nodemailer'],
};
"express-server":['express']
};

export {dependencies};

7 changes: 7 additions & 0 deletions snippets/express-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import express from "express";

const app=express();

const PORT=process.env.PORT || 3000;

app.listen(PORT, ()=> console.log(`Server started at ${PORT}`));

0 comments on commit 7180508

Please sign in to comment.