hillel-node-js

Lesson 1

Examples of different ways to export modules with Node.js and examples of async import;

Hometask 1

Simple project whitch uses different ways to export modules with Node.js, parses provided arguments and shows colorized console output.

Dependencies
  1. chalk to colorize console output
  2. minimist as argument parser
  3. cross-env to have a single command without worrying about setting or using the environment variable properly for the platform
How to start
  1. Clone the project git clone https://github.com/whitershade/hillel-node-js.git
  2. Install dependencies with npm i
  3. To run project use npm run hometask1

Hometask 2

Simple project whitch uses Node.js events and listeners.

How to start
  1. Clone the project git clone https://github.com/whitershade/hillel-node-js.git
  2. Install dependencies with npm i
  3. To run project use npm run hometask2

Hometask 3

Give a large file using the stream to the root (GET /) route; Set the response of the server with the data type that corresponds to the file (check using the file-type library); Add to the other log file the start time of the file, the end time of the file return, the number of seconds spent, and the status (successfully or aborted by the client); Every minute, write to the log file the number of requests that came to the server and their statuses.

How to start
  1. Clone the project git clone https://github.com/whitershade/hillel-node-js.git
  2. Install dependencies with npm i
  3. To run project use npm run hometask3
NOTE:

Folder logs with log files commited just to easy check сorrectness of homework.

Hometask 4

Learn how to create a web server using the http module. Make a universal web server so that it can:

Return a html page; Accept the POST request and store the received data in memory Return a JSON object or an array of objects that it has stored in memory, depending on the parameters that came to the router. Return a few pictures of different extensions with the correct 'content-type' using the stream Log the time of the request, the response, the amount of time spent, the user-agent and the status code.

How to start
  1. Clone the project git clone https://github.com/whitershade/hillel-node-js.git
  2. Install dependencies with npm i
  3. To run project use npm run hometask4

Hometask 5

Learn how to create a web server using the express module. Make a universal web server so that it can:

Return html page;

Return pictures using the stream;

Use middlewares written by the student for logging the time of the request, the response, the amount of time spent, the user-agent and the status code.

Processed the absence of a file (picture) using middlewares and return to the client a unified response.

How to start
  1. Clone the project git clone https://github.com/whitershade/hillel-node-js.git
  2. Install dependencies with npm i
  3. To run project use npm run hometask5

Hometask 6

Give the html page generated by the template;

On the html-page there should be several pictures (<img src = "file reference">), which are dynamically displayed (the server checks what files are in the folder and adds links to them in html);

On the html-page should be displayed a list of messages that are stored in memory in the form (creation time: User-message). I was able to receive a POST request and store the received object in memory;

I used intermediate handlers written by the student to validate the received data in the POST request, skipping only those that have the following structure:

{     "username": string, at least 3 characters, Latin only,

    "message": string, minimum 1, maximum 512 characters,

    "show": integer, minimum 1, maximum 60, number of seconds, how many messages will be displayed. }

(the handler also has to set several additional fields, for example, endAt: the current date in seconds + show)

Delete messages from the array whose endAt values have terminated.

Used intermediate handlers for the favicon return.

I was able to give a JSON object on request with a certain parameter or an array of objects that it has stored in memory. The return of an array of objects should also be able to sort messages according to the parameters that passed to querystring (? EndAt = asc & user = yuriy)

How to start
  1. Clone the project git clone https://github.com/whitershade/hillel-node-js.git
  2. Install dependencies with npm i
  3. To run project use npm run hometask6
  4. To run project with enabled deletion of outdated messages use hometask6-clearable

Learn how to work with the MongoDB database using the Mongoose library. Make a universal web server so that it can:

Hometask 8

Return the html page generated by the template;

On the html page, a list of messages that are taken from the MessagesCollection collection (creation time: User-Message) and the form for adding a new message should be displayed.

It should be able to receive a POST request (a new message) and store the received object in the database;

It used an intermediate handler written by the student to validate the data in the POST request, skipping only those that have the following structure:

{     "username": string, at least 3 characters, Latin only,

    "message": string, minimum 1, maximum 512 characters,

    "show": integer, minimum 1, maximum 60, number of seconds, how many messages will be displayed. }

Delete messages from the database that have endAt values.

It shoud be able to give a JSON object on request with a parameter or an array of objects from the database. Selecting objects from the database should also be able to sort and filter messages depending on the parameters that were passed to querystring (EndAt = asc & username = yuriy)

How to start
  1. Clone the project git clone https://github.com/whitershade/hillel-node-js.git
  2. Install dependencies with npm i
  3. To run project use npm run hometask8

Hometask 9

Supplement the code written in the lecture with the opportunity:

  • Display the time, name and message in the table

  • Make it possible to sort the table by time and user name (sorting must be complemented and the first sorting field should be in priority)

  • Make the message "clickable" so that it opens as a separate one with the expanded information (all fields from the database)

How to start
  1. Clone the project git clone https://github.com/whitershade/hillel-node-js.git
  2. Install dependencies with npm i
  3. To run project use npm run hometask9