Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/mavagio/node-typescript-api
- Owner: mavagio
- License: mit
- Created: 2019-12-09T13:21:45.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-20T10:27:24.000Z (almost 5 years ago)
- Last Synced: 2024-10-14T15:21:51.502Z (3 months ago)
- Topics: express, mongodb, mongoose, nodejs, typescirpt
- Language: TypeScript
- Homepage:
- Size: 56.6 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Node/Express.js/TypeScript/mongoDB
## 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.