Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/miolab/mongo_node_api
RestAPI (Node.js & MongoDB)
https://github.com/miolab/mongo_node_api
Last synced: about 2 months ago
JSON representation
RestAPI (Node.js & MongoDB)
- Host: GitHub
- URL: https://github.com/miolab/mongo_node_api
- Owner: miolab
- Created: 2020-04-21T11:36:16.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-02-05T20:57:05.000Z (almost 2 years ago)
- Last Synced: 2023-03-05T22:17:18.682Z (almost 2 years ago)
- Language: JavaScript
- Size: 305 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MongoDB & Node.js
RestAPI (Node.js & MongoDB)
- version
```
$ npm --version
6.14.4$ mongo --version
MongoDB shell version v4.2.5
```- MongoDB installed by Homebrew
---
## setting
```
$ npm init -y
```### install express
```
$ npm install express
```### init confirmation Server running
- http://localhost:3000/
```
$ node app.js
```### install nodemon
```
$ npm install nodemon
```Continuous execute Server running:
- http://localhost:3000/
```
$ npx nodemon app.js
```### install Mongoose & running MongoDB
```
$ npm install mongoose
``````
$ brew services start mongodb-community$ mongo
.
.> use test_api_db
> db.users.insertOne({name:"im", music:"avicii"})
> show dbs
> db.users.find().pretty()
{
"_id" : ObjectId("5ea0105e3496bcf020d268ce"),
"name" : "im",
"music" : "avicii"
}> exit
```### fix `app.js` (add: mongoose)
connect DB.
- restart app.js by nodemon
```
[nodemon] restarting due to changes...
[nodemon] starting `node app.js`
Test Server running http://localhost:3000
DB connection succeed.
```- if get following caution;
```
[nodemon] restarting due to changes...
[nodemon] starting `node app.js`
(node:66401) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
(node:66401) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
Test Server running http://localhost:3000
DB connection succeed.
```add following script.
```
# app.jsconst dbConnectOptions = {
useNewUrlParser: true,
useUnifiedTopology: true,
};mongoose.connect("mongodb://127.0.0.1/test_api_db", dbConnectOptions);
```