Skip to content

Commit

Permalink
feat: implemented default mongo connection to local database
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLzq committed Dec 12, 2021
1 parent 3556c10 commit 1e66e98
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ simba -a myName -e [email protected] -N myProject -D 'This is a test' -H
- This project is based in other project from my own, [`typescript-project-generator`](https://www.npmjs.com/package/typescript-project-generator), but only considering the `express-mongoose-node` part.
- You are able to run a server that has one main route, `home` (`/`), and another one, `user` (`/user` or `/user/:userId`).
- To connect your server with your `MongoDB` database, you need to provide your `uri` in the `.env`.
- To connect your server with your `MongoDB` database, you need to provide your `uri` in the `.env`. By default, we will try to connect to a local database. The content of the `.env` file is:
```bash
MONGO_URI = mongodb://mongo:mongo@mongo:27017/${projectName}
```
Where `${projectName}` will be replaced by the name of the project you provided in lowercase.
- Once you have done that, now you can perform the following `HTTP REQUEST`: `GET`, `POST`, `PATCH` and `DELETE`.
- In order to use global variables, just add the one you need in the `src/@types/index.d.ts` file, and add a new `var` with its type to the `global` interface, as follows:
```ts
Expand Down
10 changes: 5 additions & 5 deletions example/src/network/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ class Server {
console.log(`Server running at port ${PORT}`)
})

// try {
// this._mongo()
// } catch (e) {
// console.error(e)
// }
try {
this._mongo()
} catch (e) {
console.error(e)
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions lib/src/functions/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,11 @@ class Server {
console.log(\`Server running at port \${PORT}\`)
})
// try {
// this._mongo()
// } catch (e) {
// console.error(e)
// }
try {
this._mongo()
} catch (e) {
console.error(e)
}
}
}
Expand Down Expand Up @@ -1167,7 +1167,7 @@ export { response }
}
},
'.env': {
content: 'MONGO_URI = ',
content: `MONGO_URI = mongodb://mongo:mongo@mongo:27017/${projectName}`,
file: `${projectName}/.env`
},
index: {
Expand Down

0 comments on commit 1e66e98

Please sign in to comment.