So I am very happy to finally got the hang of this backend business.
Instead of simply outputting a JSON, I decided to add a very simple front-end UI as shown below.
That being said, I am hard time uploading to heroku, especially dealing with mongo database, as well as how to correctly append the right url link to direct it.
here is what my app.js looks like
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var port = process.env.PORT || 3000;
var crypto = require("crypto");
var path = require('path');
var CollectionURL = require('./models/CollectionURL.model');
var db = process.env.DB;
mongoose.connect(db);
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/',function(req,res){
res.sendFile(path.join(__dirname, 'views/index.html'));
});
app.post('/api/shorten',function(req,res){
This file has been truncated. show original
where the web host is currently reside in localhost:3000.
How do I change it to be applicable with heroku as webhost?
I used mLab to host my Mongo database and linked that up to Heroku.
This wiki entry gives a solid overview of getting started with Heroku and mLab:
In this guide let’s see how to work with MongoDB locally and with mLab for deploying it to Heroku. Alternatively you can also use mLab add-on in Heroku , It is free but it may require your credit card details. So, if you are not intrested in...
Reading time: 2 mins 🕑
Likes: 19 ❤