From ec430582c95b80ab129a574825a9239509faafae Mon Sep 17 00:00:00 2001 From: atheryx Date: Thu, 12 Oct 2023 00:09:55 +0530 Subject: [PATCH] Added .env support --- .env.example | 12 ++++++++++++ .gitignore | 1 + README.md | 8 ++++---- package-lock.json | 11 +++++++++++ package.json | 1 + src/app.js | 9 +++++---- 6 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..1123778 --- /dev/null +++ b/.env.example @@ -0,0 +1,12 @@ +# add your endpoint +YOUR_ENDPOINT='' + +# add your project ID +YOUR_PROJECT_ID='' + +# add your API Key +YOUR_API_KEY='' + + +# Use this to authenticate with JWT generated from Client SDK +# jwt='' diff --git a/.gitignore b/.gitignore index b8fc5cc..a17cb7e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules .idea **.DS_Store +.env diff --git a/README.md b/README.md index dd553be..fd48d11 100644 --- a/README.md +++ b/README.md @@ -20,13 +20,13 @@ This playground doesn't include any NodeJS best practices but rather intended to 1. Clone this repository. 2. `cd` into the repository. -3. Open the `app.js` file found in the root of the cloned repository. -4. Copy Project ID, endpoint and API key from Appwrite console into `app.js` +3. Reanme `.env.example` to `.env`. +4. Copy Project ID, endpoint and API key from Appwrite console into `.env`. 5. Run the playground: - NodeJS: + - NodeJS: - Install dependencies `npm install` - Execute the command `node app.js` - Docker: + - Docker: - Execute the command `docker compose up` 6. You will see the JSON response in the console. diff --git a/package-lock.json b/package-lock.json index 0ceec80..f11df85 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "BSD-3-Clause", "dependencies": { "chalk": "^4.1.0", + "dot-env": "^0.0.1", "node-appwrite": "^8.0.0" } }, @@ -91,6 +92,11 @@ "node": ">=0.4.0" } }, + "node_modules/dot-env": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/dot-env/-/dot-env-0.0.1.tgz", + "integrity": "sha512-SajHtzm3v7yjMH8DW9xY+4i7Zv/cN3aMtLVy0mRMuZu8L9qRCR7CNqcl4KBbG27e5Up4BpSlEyPXXLNbSAe2DQ==" + }, "node_modules/follow-redirects": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.0.tgz", @@ -229,6 +235,11 @@ "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, + "dot-env": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/dot-env/-/dot-env-0.0.1.tgz", + "integrity": "sha512-SajHtzm3v7yjMH8DW9xY+4i7Zv/cN3aMtLVy0mRMuZu8L9qRCR7CNqcl4KBbG27e5Up4BpSlEyPXXLNbSAe2DQ==" + }, "follow-redirects": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.0.tgz", diff --git a/package.json b/package.json index d4984b8..03b4595 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "chalk": "^4.1.0", + "dot-env": "^0.0.1", "node-appwrite": "^8.0.0" } } diff --git a/src/app.js b/src/app.js index 3026829..2c69cf9 100644 --- a/src/app.js +++ b/src/app.js @@ -2,13 +2,14 @@ const { Client, Databases, Functions, Account, Users, Storage, InputFile, Query, const chalk = require('chalk'); const fs = require('fs'); const path = require('path'); +require('dotenv').config(); // Config const client = new Client() - .setEndpoint('YOUR_ENDPOINT') // Replace with your endpoint - .setProject('YOUR_PROJECT_ID') // Replace with your project ID - .setKey('YOUR_API_KEY'); // Replace with your API Key - //.setJWT('jwt'); // Use this to authenticate with JWT generated from Client SDK + .setEndpoint(process.env.YOUR_ENDPOINT) // Replace with your endpoint + .setProject(process.env.YOUR_PROJECT_ID) // Replace with your project ID + .setKey(process.env.YOUR_API_KEY); // Replace with your API Key + //.setJWT(process.env.jwt); // Use this to authenticate with JWT generated from Client SDK const databases = new Databases(client); const functions = new Functions(client);