GithubHelp home page GithubHelp logo

demo-node-app's Introduction

Below is the assignment given to me by a Sydeny/Silicon valley based product company(startup)

Problem statement :

Create a node/express app with:

  • Endpoint to register an account (username/password) -- Store passwords securely
  • Endpoint to log a user in, which returns a session token
  • Express middleware function to validate the session token
  • Endpoint to receive a webhook with a stock ticker symbol and price (this needs to be unauthenticated)
  • Endpoint to return the averages of the 10 most recent prices for a given ticker symbol -- This endpoint should be authenticated
  • API bodies should use JSON
  • Use correct HTTP status codes
  • Handle exceptions
  • Add some tests
  • Feel free to use whatever libraries you like
  • No need for persistent storage - just keep everything in memory

Solution:

  • Git repo: https://github.com/nikhilyeole1/demo-node-app
  • Code has many comments to explain my thought process.
  • Creted/tested with node 12 but should work with node 10 too.
  • I have used async-await but I am good with promises too.
  • Created decoupled components(subapps / nested apps) to have separation on concerns. 'sub-apps' directory has nested mini apps. So this monolith can be easily converted to microservices in future, if required. Any sub-app should only import "service" (and nothing else) from other sub-app.
  • "$npm start" to start app.
  • "$npm test" to run tests.
  • Created integration and unit tests only for few functions to demonstrate.
  • "$npm run build:jsdocs" to generate jsdocs in jsdocs directory". Have put jsdoc comments only for few functions to demonstrate.
  • Validation of apis is done with "joi".
  • "$npm run build:apidocs" to generate api documentation. Made use of https://apidocjs.com/. New apidocs directory will be created.
  • "postman-export" directory has exported apis which can be imported in Postman and tested. Apis are listed below in short:
1.
POST /users/signup
req body:
{
  username: '[email protected]',
  password: 'pwd',
  name: 'Joe Smith' // Optional field
}

2.
POST /users/signin
req body:
{
  username: "[email protected]",
  passoword: "pwd"
}
response:
{
  sessionToken: "sdfxcedredfd" // To be sent as 'x-auth' header with authenticated /stocks/:tickerSymbol/average api.
}

3.
POST /stocks   // This is webhook that accepts ticker stock price. Is unauthenticated.
req body:
{
  tickerSymbol: 'goog',
  price: 850
}

4. GET /stocks/:tickerSymbol/average  // Is authenticated
headers
{
  x-auth: "sdfxcedredfd" // sessionToken value that we got from /users/signin api
}

demo-node-app's People

Contributors

nikhil-yeole-lenovo avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar Nikhil Advait avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.