Part #4 - (Optional) Add JSDOM
Install jsdom and typescript definitions
npm install jsdom @types/jsdom
Part #5 - (Optiona) Add Mongodb as a Datastore (excluding mongoose)
Here we will want to add the official nodejs mongodb driver from https://docs.mongodb.com/drivers/node/quick-start
Now there is a very popular npm library called mongoose which provides additional features such as defining schemas, db validations etc. I don’t personally recommend it for the following reasons:
- Defining a schema is somewhat irrelevant when using TypeScript as we can type our models
- Validation provided by mongoose is all handled at the application layer, within the nodejs app, however modern web applications often use multiple stacks, and if the database is read/updated outside the application, all those schema definitions and validations by mongoose are not used. This is the issue with application level schema validation.
- MongoDb provides db level validation, which will apply regardless of how it’s used.
- You can read more about this at https://developer.mongodb.com/article/mongoose-versus-nodejs-driver
npm install mongodb @types/mongodb