/nodejstest

Primary LanguageJavaScript

NodeJS Candidate Test

Basic knowledge questions

  • What are Promises in Node.js?

    • It's a function that can be resolved or rejected with the use of callbacks.
  • What is callback hell?

    • We're dealing with so called 'callback hell' when there's multiple promise functions nested in each other, and we heave to pass down and deal with all their callbacks.
  • What tools can be used to assure consistent style?

    • Eg Prettier, Eslint, Beautify.
  • What is REPL? What purpose it is used for?

    • It's a simple programming enviroment that is implemented in some languages (Bash, Python, Node). It can be used for simple operations, running tests or debugging.
  • What is the difference between Asynchronous and Non-blocking?

    • Async code gives you a Promise which you can await, and get for eg some data fetched from API. Non-blocking code when is executed doesn't block the execution loop of application, and is eventually executed without returning any response.
  • List types of Http requests supported by Node.js?

    • GET, POST, PATCH, PUT, DELETE, HEAD, COPY, OPTIONS
  • Is Node.js entirely based on a single-thread?

    • No, event-driven async operations are handled by multi-threaded libuv module utilized by Node.js
  • What is your favourite HTTP framework and why?

    • My favorite framework is Nestjs because it is well thought and structured, promotes best practices, comes with vast support for most common uses (integrated Multer, ORM, middlewares) and is fully written in TypeScript.
  • What is difference between JavaScript and Node.js?

    • JS is a programming language when Node.js is a JS runtime enviroment (which uses V8 engine to run JS on server). Some global variables, like document or window can be only used in JS running in browser, while for eg process is used only in Node
  • What is TypeScript? Do you use it? Why / why not?

    • TS is a superset of JS that runs on Node.js and provides support for strong typechecking
  • What are the key differences between regular and arrow functions?

    • Arrow functions doesn't have their own this, they canot be used as constructors, and they can use implicit return feature when used as one-liner (without curly braces)
  • What is destructuring?

    • Destructuring is a process of isolating objects/values from objects and arrays. Examples:
    const [val1, val2] = ["val1", "val2"];
    const {val1, val2} = {val1: "val1", val2: "val2"};
  • Explain the difference:

const a: string = "hello";
const a = "hello" as string;
  • First one provides type for a variable, and second one overrites it

Problem solving

You get an error report from testing crew - User API doesn't return "Test User" data for ID: 1. Code is in this repository.

Find out why, fix it and write report on why did it happen.

The report

Findings:

  1. ID of the user was 0, not 1
  2. There was wrong module imported: unfinished models/index.js instead of mocked models/users.js
  3. if statement was changed from user_id === 0 to user_id === 1

Commit with changes.

Create something whilst learning something new

For this task you will need your personal account in AWS. Please create one if you don't have it yet (do not worry about costs, everything you do here will covered by AWS Free Tier).

  • Create a REST API in AWS API Gateway.
  • Create 2 HTTP methods in the API: GET & POST.
  • Create a DynamoDB Table (keep provisioned WCU & RCU low to stay within Free Tier, 2 will be OK) and name it "users". It should consist only of a parition key (hash key) which is "user_id".
  • Create a lambda function and integrate it with the API POST method. In the JSON body of HTTP POST request, user should be able to specify his first name and age. Lambda should take provided body and insert it into your DynamoDB table as a new item. Value for user_id column should be generated as a random GUID and returned to the caller in the response.
  • Create second lambda function and integrate it with the API GET method. GET method should take a user_id as path parameter. Lambda should lookup the DynamoDB table (using query method!) and either return user or 404 status code if it doesn't exist.

Please create a new GitLab/GitHub repository, upload your lambda code in there and share link to the repo with us. Repository should also contain a README.md with URLs to your API GET & POST methods and explanation about how to use them (exact paths, example body for POST method).

Files and README.md for this task are placed under lambda_functions/ directory within this repository.