yarn init -y
yarn add express body-parser mongodb mongoose nodemon
touch index.js
mongod
yarn start
- write your code
- Visit https://cloud.mongodb.com/ and sign up, choose "FREE"
- Cloud Provider & Region, choose AWS (default)
- Region, choose N. Virginia us-east-1 (default)
- Cluster Tier, choose M0 Sandbox (default)
- Cluster Name, name it something relevant to your app
- Click "Create cluster"
- Left panel, click "Database Access"
- Click "Add New Database User"
- Authentication Method, choose "Password" (default)
- Password Authentication, username: "admin", password: whatever you want
- Database User Privileges, choose "Atlas admin"
- Click "Add User"
- Left panel, click "Network Access"
- Click "ALLOW ACCESS FROM ANYWHERE"
- Click "Confirm"
- Left panel, click "Clusters"
- Click "Connect"
- Click "Connect your application"
- Copy the url to
index.js
in VSCode and replace the string where we havemongoose.connect('mongodb://localhost:27017/something')
, the is what you decided in step 10, the you're making it up right now, name it something relevant - Save file then git add, git commit, and git push this change
- Visit https://heroku.com and sign up
- Click "New" then "Create new app"
- Give it a name then click "Create app"
- Click "Github Connect to Github"
- Search for a repository to connect to, type the repo and click "Search"
- Click "Connect"
- Click "Enable Automatic Deploys"
- In VSCode, change
index.js
whereapp.listen(3001
toapp.listen(process.env.PORT || 3001
- Save file then git add, git commit, and git push this change
- Visit your app i.e. https://tracking-system-api.herokuapp.com/api/v1/users (notice the
/api/v1/
), should see an empty array until you put some data into your database that's hosted on mongodb. If you see "Application error" that's not good. Repeat the steps or ask for help.
While you can deploy your frontend to Heroku, I strongly recommend Netlify to work around Heroku's free 1000 hour / month limit. Visit https://github.com/robghchen/tracking-system for instructions.