From 760c4a967df6db9b6609b6b896862a60d33dc7a7 Mon Sep 17 00:00:00 2001 From: Lavavarshney Date: Wed, 30 Oct 2024 18:18:32 +0530 Subject: [PATCH 1/4] Added snippet for setting express server,updated README.md and snippet dependencies --- README.md | 28 +++++++++++++++++++++------- index.js | 2 +- snippetdependencies.js | 4 +++- snippets/express-server.js | 7 +++++++ 4 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 snippets/express-server.js diff --git a/README.md b/README.md index d8c0850..8600dd8 100644 --- a/README.md +++ b/README.md @@ -83,8 +83,22 @@ 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. **`express-setup`**: +Sets up express server. -1. **`async-ops-handler`**: +**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**: @@ -100,7 +114,7 @@ This command will create a new file `multer-file-upload.js` in the current worki export { asyncHandler } ``` -2. **`custom-api-error`**: +3. **`custom-api-error`**: Standardizes error responses for your API. **Code Snippet**: @@ -129,7 +143,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**: @@ -146,7 +160,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**: @@ -165,7 +179,7 @@ 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**: @@ -183,7 +197,7 @@ This command will create a new file `multer-file-upload.js` in the current worki ``` -6. **`mongoose-schema`**: +7. **`mongoose-schema`**: Sets up a basic schema for your db using `mongoose`. **Code Snippet**: @@ -200,7 +214,7 @@ This command will create a new file `multer-file-upload.js` in the current worki ``` -7. 6. **`nodemailer`**: +8. 6. **`nodemailer`**: Sets up email functionality in Node.js projects **Code Snippet**: diff --git a/index.js b/index.js index 5e258ef..273b715 100644 --- a/index.js +++ b/index.js @@ -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'; diff --git a/snippetdependencies.js b/snippetdependencies.js index f21f6db..1e974e4 100644 --- a/snippetdependencies.js +++ b/snippetdependencies.js @@ -3,6 +3,8 @@ const dependencies = { "mongoose-schema" : ['mongoose'], "multer-file-upload" : ['multer'] , "nodemailer": ['nodemailer'], - }; + "express-setup":['express'] +}; + export {dependencies}; \ No newline at end of file diff --git a/snippets/express-server.js b/snippets/express-server.js new file mode 100644 index 0000000..14f6004 --- /dev/null +++ b/snippets/express-server.js @@ -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}`)); \ No newline at end of file From 78a237294be1d6a5334b93e6ce8643a5b6b9be3b Mon Sep 17 00:00:00 2001 From: Lavavarshney Date: Fri, 1 Nov 2024 14:12:14 +0530 Subject: [PATCH 2/4] Updated README.md --- README.md | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 99869d2..afbde86 100644 --- a/README.md +++ b/README.md @@ -87,19 +87,15 @@ This command will create a new file `multer-file-upload.js` in the current worki ### Available Snippets 1. **`express-server`**: -Sets up express server. - -**Code Snippet**: + 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}`)); - - ``` + 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. From d32f5985cecbf1fc4a78b4a3ff6bf4ab8734c978 Mon Sep 17 00:00:00 2001 From: Lavavarshney Date: Fri, 1 Nov 2024 14:29:08 +0530 Subject: [PATCH 3/4] Updated README.md --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index afbde86..da6d8af 100644 --- a/README.md +++ b/README.md @@ -97,26 +97,23 @@ This command will create a new file `multer-file-upload.js` in the current worki app.listen(PORT, () => console.log(`Server started at ${PORT}`)); ``` -2. **`async-ops-handler`**: +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 }; ``` -3. **`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 = '') { From 91959320a9baffbf0563e20e35cc92627421979a Mon Sep 17 00:00:00 2001 From: Lavavarshney Date: Fri, 1 Nov 2024 16:53:58 +0530 Subject: [PATCH 4/4] Corrected filename --- snippetdependencies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippetdependencies.js b/snippetdependencies.js index 1e974e4..2ab3e4a 100644 --- a/snippetdependencies.js +++ b/snippetdependencies.js @@ -3,7 +3,7 @@ const dependencies = { "mongoose-schema" : ['mongoose'], "multer-file-upload" : ['multer'] , "nodemailer": ['nodemailer'], - "express-setup":['express'] + "express-server":['express'] }; export {dependencies};