diff --git a/.env b/.env index 909d9c39c679f3a0241b8ff8ec849d5ab241cf03..ea7b45a8af34becd189681797943db2363b8083d 100644 --- a/.env +++ b/.env @@ -1,4 +1,4 @@ -PORT=3001 +PORT= 3001 MONGODB_URI=mongodb://localhost:27017/notificationapp DB_NAME=notificationapp NAME=notification-service \ No newline at end of file diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 66b7814b4e05c47c35b7102eb9452d61ac51cc61..4c6e7d3feed4cbc9b90afaafefc4d2fa40561395 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -229,6 +229,14 @@ "npm": "1.2.8000 || >= 1.4.16" } }, + "node_modules/dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", + "engines": { + "node": ">=12" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", diff --git a/package-lock.json b/package-lock.json index 3cba06a5d6caa42f42888398389f17a38ad2b387..b9f88047452b2b26c701a107a1b1a1d29745cef1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "dotenv": "^16.0.3", "express": "^4.18.2", "mongoose": "^7.0.3", "nodemon": "^2.0.22" @@ -239,6 +240,14 @@ "npm": "1.2.8000 || >= 1.4.16" } }, + "node_modules/dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", + "engines": { + "node": ">=12" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", diff --git a/package.json b/package.json index eb14ed10cd3be9ecb152a3873133e723a06c6193..011519968819cdf0edfd1212b9b3b82c5179d3ae 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "author": "Alan", "license": "ISC", "dependencies": { + "dotenv": "^16.0.3", "express": "^4.18.2", "mongoose": "^7.0.3", "nodemon": "^2.0.22" diff --git a/src/index.js b/src/index.js index cd28125fd62a51dfa428a33c4f0fe8a7e26cb3aa..85fef6b70d0ab41ec11d7e75a7157157f93b0e4e 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,6 @@ // import { MongoClient } from "mongodb"; -// const connectionString = process.env.ATLAS_URI || ""; require('./db/mongoose'); +require('dotenv').config(); const express = require('express'); //const Notification = require('./schema/schema') diff --git a/src/routes/notification.js b/src/routes/notification.js index fbe6c86cee572f6bdfe07766625f32106c54ed72..8e37e7ed2ca3053ab24e47d88c32c06566a5cd7a 100644 --- a/src/routes/notification.js +++ b/src/routes/notification.js @@ -66,7 +66,11 @@ router.get("/info/:id", async (req,res) =>{ router.post("/create", async (req,res) => { //recieve the notifcation info from the user // send the notifcation to the database (create/save/insert methods) - const notifications = new Notification(req.body); + //const notifications = new Notification(req.body); + + const date = new Date; + const notifications = new Notification({ userid: req.body['userid'], title: req.body['title'], description: req.body['description'], date: date }); + try{ await notifications.save(); res.status(201).send(notifications);