blogging-challenge-node

Table of Contents

Created by gh-md-toc

Description

Create a minimal expression (from your perspective) of a blogging platform. (Only the backend)

Context

Full detailed instructions here: challenge-node-js.pdf

Technology Stack

The different technologies that we used in the project are:

  • Node JS
  • Express JS
  • MongoDB

Development dependencies

Additional to those techs, we add some components and development dependencies:

  • Nodemon as development server.
  • Awilix to handle DI ascross the app layers.
  • Mocha as a testing framework.
  • Mongoose for object data modeling.
  • ESLint to improve code quality.
  • Other depdencies: CodeCov, supertest, dotenv, etc.

Development environment

To run the project locally cover this topics.

Requirements

  • Node version v10.x.x. (v10.15.3 was used)
  • Yarn
  • MongoDB. (get from here)
  • Some sort of REST Client. (Advance REST Client, Insomnia, etc)

Environment variables

Look for .env.example, copy and rename to .env, and replace the values with these values:

REST_API_PORT=3000
MONGODB_HOST=localhost
MONGODB_PORT=27017
MONGODB_DBNAME=blog
TEST_MONGODB_HOST=localhost
TEST_MONGODB_PORT=27017
TEST_MONGODB_DBNAME=blog-test

Install

๐Ÿ‘พJust run yarn command and thats it.

Scripts

๐Ÿ“ Here is the list of commands available for the project.

Name Command Description
start yarn start Starts the /api endpoint, go open your http://localhost:3000 and enjoy. ๐Ÿš€
lint yarn run lint Runs the linter task to look for code smells and improvements. ๐Ÿ‘น
test yarn run test Runs the test suite for the blogging app. ๐Ÿค–

Challenge tasks

๐Ÿ’ฐ For the MVP of the Blogging App we cover these requirements:

  • Http server developed in Node.
  • /api/posts endpoints that basic REST operations.

Routes

๐ŸŽข /api/posts REST operations.

Endoint Type Description Params/Body Response
/api/posts GET Get the list of posts. Param: ?q= (optional) List of filtered posts.
/api/posts POST Create a new post. Body: <Post object> Persisted post object.
/api/posts/:id GET Get a post by id. Param: :id Post object.
/api/posts/:id DELETE Remove a post. Param: :id Remove post object.
/api/posts/:id PUT Update a post. - Param: :id Update post object.
Body: <attrs object>

Mongo database

๐Ÿ’พ The blog database contains a single collection with the post definition.

Field Type Description
title String The title
text String The text
author String The status enum: draft, private, public

Extras

๐ŸŒถ For additional flavor to the blogging app we add these:

  • A built-in enum attribute on mongoose, to support the post status. #๏ธโƒฃ
  • Mocha tests to cover the blog post CRUD operations. โ˜•๏ธ
  • Linter to look for code smells and improvements. ๐Ÿ‘น
  • Text search across all of the post attributes. (single q= param to rule them all. ๐Ÿ’)

Future steps

๐Ÿฆ„ For future steps we can consider these items:

  • Add more tests to cover the diferent layers of the app. (services, models)
  • Create a UI, maybe in React, to use the /api endpoint.
  • Add security and user identification.