Week 3 Backend - Plous01/ProjectTech GitHub Wiki

Data (feature)

This week, I have worked on receiving user input and manipulating data for my own Job Story (Add new users to an overview list of people, filter).

NPM Packages

Slug

Slugifies every string, even when it contains unicode!

Example:

var slug = require('slug')
var print = console.log.bind(console, '>')
 
print(slug('i ♥ unicode'))
// > i-love-unicode
 
print(slug('unicode ♥ is ☢')) // yes!
// > unicode-love-is-radioactive
 
print(slug('i ♥ unicode', '_')) // If you prefer something else then `-` as seperator
// > i_love_unicode
 
slug.charmap['♥'] = 'freaking love' // change default charmap or use option {charmap:{…}} as 2. argument
print(slug('I ♥ UNICODE'))
// > I-freaking-love-UNICODE
 
print(slug('☏-Number', {lower: true})) // If you prefer lower case
// > telephone-number
 
print(slug('i <3 unicode'))
// > i-love-unicode

Bodyparser

This is a node.js middleware for handling JSON, Raw, Text and URL encoded form data.

To handle HTTP POST request in Express.js version 4 and above, you need to install middleware module called body-parser.

Body-parser extract the entire body portion of an incoming request stream and exposes it on req.body

The middleware was a part of Express.js earlier but now you have to install it separately.

This body-parser module parses the JSON, buffer, string and URL encoded data submitted using HTTP POST request.

The bodyParser object exposes various factories to create middlewares. All middlewares will populate the req.body property with the parsed body when the Content-Type request header matches the type option, or an empty object ({}) if there was no body to parse, the Content-Type was not matched, or an error occurred.

Multer

Multer is a node.js middleware for handling multipart/form-data, which is primarily used for uploading files.

Multer adds a body object and a file or files object to the request object. The body object contains the values of the text fields of the form, the file or files object contains the files uploaded via the form.

Resources

Slug

Body-parser Stackoverflow

Middleware in Express

Multer

app.get vs app.use Stackoverflow