![]() Var MongoClient = require('mongodb').MongoClient The controller below is meant to write this form data to the MongoDB database. Please note I have not included the other routes and controllers but they simply submit a Form via the POST method to /data/submit. I have tried to pass the "db" object through to the router (dataRoutes.js) but I cannot figure how to make this accessible to the controller (data.js). I understand why this is - the db object is not being "passed" through to the router and then subsequently through to the controller. ![]() I am having problems trying to access the "DB" database object that is created when the MongoDB client module connects to my MongoDB database.Īt the moment I am getting an error stating that, within data.js, 'db' is not defined. Install dev dependencies npm install -save-dev nodemon Mongoose: ODM for connecting and sending queries to a mongo databaseĬors: adds cors headers so our frontend app can make requests Mercedlogger: A library I created for colorful logs Morgan: library for logs that can be helpful for debuggingĭotenv: library to allow for use of. Jsonwebtoken: library for signing/creating and verifying/validating JSON Web Tokens (JWT), often pronounced 'JOT' for some reason.īcryptjs: library for hashing strings like password and then comparing the hash to strings for validation. Install dependencies npm install express jsonwebtoken bcryptjs morgan dotenv mercedlogger mongoose cors You can add more layers of complexity if you wish (user roles, refresh tokens, etc.). ![]() This article is a walkthrough to creating a basic level of authentication with Express, Mongo and JSON Web Token. ![]() ![]() REPO OF CODE FROM THIS LESSON HERE AS A TEMPLATE ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |