From 743bb900bb7728d67846dd9ed6bd5b425eb0dfc0 Mon Sep 17 00:00:00 2001 From: Tor Andreas Johnsen Date: Mon, 29 Oct 2018 22:16:41 +0100 Subject: [PATCH 1/4] Update with es6 --- server.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/server.js b/server.js index ab0929d..90c6aa1 100644 --- a/server.js +++ b/server.js @@ -1,15 +1,13 @@ 'use strict'; -var express = require('express'); -var mongo = require('mongodb'); -var mongoose = require('mongoose'); - -var cors = require('cors'); - -var app = express(); +const express = require('express'), + mongo = require('mongodb'), + mongoose = require('mongoose'), + cors = require('cors'), + app = express(); // Basic Configuration -var port = process.env.PORT || 3000; +const port = process.env.PORT || 3000; /** this project needs a db !! **/ // mongoose.connect(process.env.MONGOLAB_URI); @@ -19,19 +17,19 @@ app.use(cors()); /** this project needs to parse POST bodies **/ // you should mount the body-parser here -app.use('/public', express.static(process.cwd() + '/public')); +app.use('/public', express.static(`${process.cwd()}/public`)); -app.get('/', function(req, res){ - res.sendFile(process.cwd() + '/views/index.html'); +app.get('/', (req, res) => { + res.sendFile(`${process.cwd()}/views/index.html`); }); // your first API endpoint... -app.get("/api/hello", function (req, res) { +app.get("/api/hello", (req, res) => { res.json({greeting: 'hello API'}); }); -app.listen(port, function () { +app.listen(port, () => { console.log('Node.js listening ...'); -}); \ No newline at end of file +}); From dca8dc92fd29783e3dd3a8b932423f6297e9a48c Mon Sep 17 00:00:00 2001 From: Abhijeet Singh Date: Fri, 30 Nov 2018 00:04:34 +0530 Subject: [PATCH 2/4] Update server.js --- server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index ab0929d..60fd27a 100644 --- a/server.js +++ b/server.js @@ -12,7 +12,7 @@ var app = express(); var port = process.env.PORT || 3000; /** this project needs a db !! **/ -// mongoose.connect(process.env.MONGOLAB_URI); +mongoose.connect(process.env.MONGOLAB_URI, { useMongoClient: true }); app.use(cors()); @@ -34,4 +34,4 @@ app.get("/api/hello", function (req, res) { app.listen(port, function () { console.log('Node.js listening ...'); -}); \ No newline at end of file +}); From 680fb45533f65def908a0218b2ff9b3f924f6cca Mon Sep 17 00:00:00 2001 From: shubhneet182 <44540772+shubhneet182@users.noreply.github.com> Date: Tue, 1 Oct 2019 23:36:13 +0530 Subject: [PATCH 3/4] Added Node.js documentation +Doc Improvements Adding Node.js documentation link for beginners, fix grammatical error, spacing and highlighting some keywords. --- views/index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/views/index.html b/views/index.html index 4681b0b..ed7d471 100644 --- a/views/index.html +++ b/views/index.html @@ -14,10 +14,10 @@

API Project: URL Shortener Microservice

User Story:

    -
  1. I can POST a URL to [project_url]/api/shorturl/new and I will receive a shortened URL in the JSON response.
    Example : {"original_url":"www.google.com","short_url":1}
  2. -
  3. If I pass an invalid URL that doesn't follow the http(s)://www.example.com(/more/routes) format, the JSON response will contain an error like {"error":"invalid URL"}
    - HINT: to be sure that the submitted url points to a valid site you can use the function dns.lookup(host, cb) from the dns core module.
  4. -
  5. When I visit the shortened URL, it will redirect me to my original link.
  6. +
  7. I can POST a URL to [project_url]/api/shorturl/new and I will receive a shortened URL in the JSON response.

    Example : {"original_url":"www.google.com","short_url":1}


  8. +
  9. If I pass an invalid URL that doesn't follow the http(s)://www.example.com(/more/routes) format, the JSON response will contain an error like {"error":"invalid URL"}

    + HINT: To be sure that the submitted URL points to a valid site, you can use the function dns.lookup(host, cb) from the dns core module. Incase you are new to NodeJs, you can learn about this function from its documentation.(NodeJs Documentation)


  10. +
  11. When I visit the shortened URL, it will redirect me to my original link.

Short URL Creation

@@ -45,4 +45,4 @@ - \ No newline at end of file + From c73327be88aa712662f8969e7293c8f99d9845df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20=C3=87a=C4=9Fatay=20Tulun?= Date: Fri, 11 Oct 2019 22:00:30 +0300 Subject: [PATCH 4/4] Changed URL in the creation example to make it consistent with usage example. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8c745aa..b60f60d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ #### Creation Example: -POST [project_url]/api/shorturl/new - body (urlencoded) : url=https://www.google.com +POST [project_url]/api/shorturl/new - body (urlencoded) : url=https://www.freecodecamp.org/forum/ #### Usage: