Hi campers,
I have an issue with this challenge.
Here is the code that I am working with
'use strict';
var express = require('express');
var mongo = require('mongodb');
var mongoose = require('mongoose');
var cors = require('cors');
var bodyParser = require('body-parser');
var urlHandler = require('./controllers/urlHandler.js');
var app = express();
var mongoURL = process.env.MONGOLAB_URI;
var port = process.env.PORT || 3000;
mongoose.connect(mongoURL);
app.use(cors());
app.use(bodyParser.urlencoded({'extended': false}));
app.use('/public', express.static(process.cwd() + '/public'));
app.get('/', function(req, res){
res.sendFile(process.cwd() + '/views/index.html');
});
app.post('/api/shorturl/new', urlHandler.addUrl);
app.get('/api/shorturl/:shurl', urlHandler.processShortUrl);
app.use(function(req, res, next){
res.status(404);
res.type('txt').send('Not found');
});
app.listen(port, function () {
console.log('Node.js listening ...');
});
… and in my .env I have following
MONGOLAB_URI='mongodb://admin:admin1@ds139950.mlab.com:39950/short-url'
Here is my package.json ; just in case if you need it.
{
"name": "shorturl",
"version": "0.0.1",
"description": "API project for freeCodeCamp",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^5.0.0-alpha.2",
"mongodb": "^3.0.8",
"mongoose": "^5.1.3",
"cors": "^2.8.4",
"body-parser": "^1.18.3",
"node": "^10.3.0"
},
"engines": {
"node": "8.11.2"
},
"repository": {
"type": "git",
"url": "https://hyperdev.com/#!/project/welcome-project"
},
"keywords": [
"node",
"hyperdev",
"express"
],
"license": "MIT"
}
Can someone, please, help me get over this hurdle. I have been working on this project for DAYS and I can not figure out what am I doing wrong with following all the tutorials and everything that I was able to find online.
Thank you in advance for any help.