Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mavagio/node-typescript-api

Node + Express.js + TypeScript + mongoDB
https://github.com/mavagio/node-typescript-api

express mongodb mongoose nodejs typescirpt

Last synced: 28 days ago
JSON representation

Node + Express.js + TypeScript + mongoDB

Awesome Lists containing this project

README

        

# Node/Express.js/TypeScript/mongoDB

nodejs
TypeScritpt
Mongo


## Getting started
Before starting the API locally make sure you have:
- [Node.js](https://nodejs.org) installed
- Have mongoDB running locally (You can also provision mongoDB instance as a service and the URI to connect to it, see next section)

Install dependencies:
```
npm i
```
Start the API
```
npm run start:dev
```

You can now navigate to `http://localhost:3000/api/user` endpoint,

The following makes a request to `/user` endpoint to retrieve all the entries for users model in the database.

You can post a new entry to the same endpoint using e.g. [Postman](https://www.getpostman.com/).

Post:
```
http://localhost:3000/api/user
```
Request Body
```
{
"name": "YourName",
"email": "[email protected]",
"type": 1
}
```

## Connect database-as-a-service
Connect provisioned mongoDB instance (e.g. [MLab](mlab.com)) by providing the host URI in the `.env` file:

Create `.env` file in the root directory (note: do not commit any secrets)

```
PORT=3000
NODE_ENV='development'
PROD_DB='mongodb://:@.mlab.com:/'
DEV_DB='mongodb://localhost/dbname'
```

Start the the API using `npm run start:prod` the program will pick up the MongoDB URI from `.env` file.