Express.js Node.js application with a config file, static file serving, POST/JSON request handling, cookies, and MongoDB.
Requirements:
- Node.js https://nodejs.org/
- NPM https://www.npmjs.com/
- GitHub
- A browser
- MongoDB 2.6.x https://www.mongodb.org/downloads#previous
Follow these instructions to launch:
- Use GitHub to clone branch to a local folder
- Launch terminal/cmd and
cd
to the local folder - Use NPM to install by running
npm install
in terminal/cmd - Launch mongod
mongod --dbpath /path/to/mongo/data
- Run using Node.js
node app.js
- If all went well, open a browser and navigate to
http://localhost:8080
Additional:
- Navigate to
http://localhost:8080/cookies
to see all signed cookies - Navigate to
http://localhost:8080/cookies/set
to set cookieVal to 0 for 5 minutes. Repeat to increment the cookieVal. - Navigate to
http://localhost:8080/cookies/unset
to clear cookieVal. - Navigate to
http://localhost:8080/mongo
to add a message to mongodb. Once a value is submitted, navigate back to see all submitted values.
Bonus:
- Edit the config file to change the port to 1337
- Run using Node.js
node app.js
- Navigate to
http://localhost:1337
- Send GET/POST/JSON to
http://localhost:8080/data
to see it work. - Toggle settings in the config file.
- Get the cookies to last 30 minutes instead of 5.
- Play with the cookie settings in the config file. Note: if you turn off signed cookies, get the cookie values from req.cookies instead of req.signedCookies.