API with Node and Mongoose.
- The default production git branch is
master
. - The web server is running with Node and Express.
- The database configured is MongoDB and "driver" is Mongoose.
- The authentication is JWT (Json Web Token).
- The web listener only starts after database connect.
- The New Relic dependency is added, and so on if you don't want configure remove
require
of new relic onapp.js
.
Installing Heroku CLI:
sudo snap install --classic heroku
Login on Heroku CLI, configure project and star deploy. You must change every app name bcg-node-mongo-api
as a unique name.
heroku login
heroku create bcg-node-mongo-api
git push heroku master
Must configure on Heroku Dashboard the configured environment variables or with Heroku CLI as heroku config:set ATTRIBUTE_NAME=value
Configuring without the newrelic.js file, can be done by following config environment variable, with properly attributes.
heroku addons:create newrelic:wayne -a bcg-domain-core
heroku config:set NEW_RELIC_LICENSE_KEY=<Add your license key>
heroku config:set NEW_RELIC_APP_NAME=<Insert your app name>
Run command on project source folder as following:
docker-compose up -d
You can create environment variables manually or create a file .env
copy as .env.example
and fulfill as needed.
On for configure MONGO_URI
follow the file env.example
and you should configure the IP Address of container docker. For this, run:
docker inspect <id or name container> | grep "IPAddress"
Get the value as 172.25.0.3
and replace ip on MONGO_URI
.
We'll go inside docker container, connect to MongoDB as root, create a user for app connection. Run this command:
docker exec -i -t <id or name container> /bin/bash
mongodb -u- root -p
# password: example
use bcg
db.createUser(
{
user: "user_db",
pwd: "password_db",
roles: [
{ role: "readWrite", db: "bcg" }
]
})
Generate Swagger Documentatio and run as dev
npm run swagger
Run as monitor
npm run dev
The port can change as the PORT
environment variable changes.
http://localhost:3000/docs
Management with MongoDB Express, available on http://localhost:8081/.
{
"dev": "nodemon app.js",
"start": "node app.js",
"swagger-autogen": "rm -rf swagger-api-specification.json && node swagger.js",
"swagger": "npm run swagger-autogen && npm run dev"
}
Reporting throght New Relic.
You'll must search for the app on New Relic APM Dashboard.
Access on https://newrelic.com/, or direct link to Dashbord ATM