diff --git a/README.md b/README.md index 1f38071..d974f3b 100644 --- a/README.md +++ b/README.md @@ -33,3 +33,16 @@ make sure admin access - to start server "C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe" + +## Deploy + +### Heroku + +1. Fork this repository +1. Create a free Heroku Account +1. Create free heroku app with your github fork + +## Roadmap + +- A login Screen +- protected routes with JWT diff --git a/package.json b/package.json index 72dd23d..ef6fb0f 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "A url shortner", "main": "index.js", "scripts": { + "start": "node ./server.js", "devStart": "nodemon server.js" }, "repository": { diff --git a/server.js b/server.js index d64dce4..193a2b4 100644 --- a/server.js +++ b/server.js @@ -12,7 +12,9 @@ app.use(express.urlencoded({ extended: false })); // to connect to database const mongoose = require("mongoose"); -mongoose.connect("mongodb://localhost/db", { + +//App deploy or localhost mode connection to MongoDB +mongoose.connect(process.env.MONGO_URL || "mongodb://localhost/db", { useNewUrlParser: true, useUnifiedTopology: true, }); @@ -46,7 +48,8 @@ app.get("/:shortUrl", async (req, res) => { //otherwise increase the click shortUrl.clicks++; //save the changes in table - shortUrl.save(); + //can use `await` here but speed of redirect is more important + await shortUrl.save(); //redirect the full link corresponding the short url we found res.redirect(shortUrl.full);