Git Product home page Git Product logo

send-me-text-students's Introduction

TEXT-TO-SERVER

We want to create a form that will be able to send text to a server we'll also implement. You need to open with Live Server the client in order to make this work.

Resources:

  • NodeJS URL module - Link
  • NodeJS Http module - Link
  • File System module - Link
  • Check if file exists in NodeJS - Link

Video describing this exercise (Spanish) - Link

Requeriment 1

Create a server in your local machine that will be listening to incoming requests in port 3000. Submit the form for the first time with any information. Is the server receiving all the fields from the form?

Requeriment 2

The server should always work if the incoming request is to the endpoint /sendtext and only if the client is performing a GET request. In any other case, it should respond back a 404 error with a messsage of your choice.

To pass this requirmenet, just try to console.log que content parameter that you receive from the client GET request.

Requeriment 3

The server should write information to a file everytime it receives a petition.

  1. If the filename.txt written by the user does not exists; the server will create a new file with the information coming from the content field
  2. If the filename.txt already exists, the new information coming from content should be appended at the end of the file.

The filename can be stored in the same folder that app.js.

Requermient 4

Submit a new form entry with this infromation: Filename: duckduckgo Content: this is just a test.

Now, try to navigate to http://localhost:3000/duckduckgo.txt. Can you see the file? Why or why not?

Requeriment 5

Open a new Git Bash terminal in your server project folder

  1. Write a command to show all the files with TXT extension sorted by modification date.

  2. Write another command to watch every second the files sorted by modification date. Perform a new submit in the form and notice if the file list is updated

BONUS

  1. Store your files in path named files; instead of the root directory of the server.

  2. Use the Path module to create the path to the filename you want to store, insted of concateneiting strings.

  3. Introduce some client validation to avoid the user to input more that 1024 caracters in the contect field form. Add also some server validation: if the server receives a content with more than 1024, it should response an 500 error; with a message informing the client that the text submitted is too long.

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.