Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.
/ express-ts Public archive

Getting started with Express, TypeScript, MongoDB and Jest

License

Notifications You must be signed in to change notification settings

Raul6469/express-ts

Repository files navigation

express-ts Build Status codecov Maintainability Codacy Badge

This is an attempt to build a simple REST API with Express, TypeScript and MongoDB, and unit testing with Jest. Feedback and contributions welcome!

Execution

You will require these programs installed on your machine:

  • NodeJS and npm
  • MongoDB

You can use Postman to test the API endpoints.

  1. Install required dependencies with npm install
  2. Create a db folder in the project root and start MongoDB with mongod --dbpath=db
  3. Create a .env file based on the .env.example. You can change the parameters if you want
  4. Initialize the database data by running npm run init-db
  5. Start the server with npm start

Usage

Authentication

You will have to provide a JSON Web Token to access the protected endpoints:

POST /auth

Body:

{
	"username": "raul",
	"password": "pwd"
}

Provide the following header in each of your requests:

Authorization: Bearer <your token>

Messages

You can create and view messages that will be stored in the database:

POST /message

Body:

{
	"message": "test"
}

And to get the list of existing messages:

GET /message

Testing

npm test

Releases

No releases published

Packages

No packages published