So, we have everything set out; let's build the app.
Let's create our package.json
file.
Here are the packages we require:
body-parser
express
mongoose
Let's install them. Run this command under your project directory to install the dependencies:
npm install --save body-parser express mongoose
This is what my package.json
looks like:
{ "name": "url-shortener", "version": "1.0.0", "description": "A NodeJS + Express + MongoDB based URL shortener", "main": "app.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "author": "shahid", "license": "MIT", "dependencies": { "body-parser": "^1.14.1", "express": "^4.13.3", "mongoose": "4.2.9" } }
Let's create the configuration file. Name it config.js
and place the code, shown as follows:
var config = {}; config.db = {}; config.webhost = 'http://localhost:3000/'; config.db.uri...