Minimal personal page for graphic designer Julian Humm featuring an interactive ripple effect background.
by Rob Hope @robhope via One Page Love
"Mr Branding" is a blog based on RSS for everything related to website branding and website design, it collects its posts from many sites in order to facilitate the updating to the latest technology.
To suggest any source, please contact me: Taha.baba@consultant.com
Minimal personal page for graphic designer Julian Humm featuring an interactive ripple effect background.
Express is a popular Node.js web framework. Amongst its functionality, it provides a wrapper for Routing. The Express Router helps in the creation of route handlers. In this tutorial, you will learn how to work with Express Router.
Let's get started.
Create a new directory for your application. Run the command to initialize npm in the directory you just created.
npm init -y
The only dependency you will need is express, so go ahead and install it.
npm install --save express
At the end, your package.json file should look like this.
#package.json { "name": "express-router", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "express": "^4.16.2" } }
Now create a new file called index.js, which will be your entry file as stated in your package.json.
For now, you just need a basic setup like this:
#index.js const express = require('express') const app = express() app.listen(3000, () => { console.log(`Server running at port 3000`) })
Start by creating some basic routes as I have below.
#index.js ... const router = express.Router() // 1 router.get('/', (req, res) => { // 2 res.send('This is the homepage!') }) router.post('/contact', (req, res) => { // 3 res.send('This is the contact page with a POST request') }) app.use('/', router) // 4 ...
'/'
. If you fail to mount a path on this middleware, it will be executed for every request made to the app.Let's say you had the code below instead.
app.use('/user', router)
This will match all the following: /user/profile, user/profile/edit, user/dashboard/article/view, and so on.
In the above code, you attached a route method to an instance of Express Router. The route method is derived from one of the HTTP methods and attached to the instance of the Express Router as you did.
Express supports the following routing methods that correspond to HTTP methods: get, post, put, head, delete, options, trace, copy, lock, mkcol, move, purge, unlock, report, mkactivity, checkout, merge, m-search, notify, subscribe, unsubscribe, patch, and search.
There is a routing method app.all()
which is not derived from any HTTP method. This routing method gets loaded for functions at a specified path for all request methods.
Say you have the code below in your application.
app.all('/books', (req, res) => { res.send('This accesses the book section') })
This will be executed for requests to "/books" when you are using GET, POST, PUT, or any HTTP request method.
A route path is used to define an endpoint where requests can be made. It does so with the combination of a request method. In Express, route paths can be string patterns or regular expressions.
Here are examples you can add to your index.js file.
#index.js router.get('/about', (req, res) => { res.send('This route path will match to /about') }) router.get('/profile.txt', (req, res) => { res.send('This route will match to /profile.txt') })
Let's see a route path using string patterns.
router.get('/ab+xy', (req, res) => { // 1 res.send('ab+xy') }) router.get('/ab(xy)?z', (req, res) => { // 2 res.send('/ab(xy)?z') })
These are used to capture values that are specified at a certain position in the URL. They are called URL segments. The values captured are made available in the req.params
object, using the name of the route parameter specified in the path as the keys of the values.
Here is an example.
If you have a route path similar to this in your application: /users/:userId/articles/:
articleId
The requested URL will look like this: http://localhost:3000/users/19/articles/104
In the req.params, the following will be available: { "userId": "19", "bookId": "104" }
Go ahead and create a new route in your application, using the route path above.
router.get('/users/:userId/articles/:articleId', (req, res) => { res.send(req.params) })
Start your server and point your browser to http://localhost:3000/users/19/articles/104. You will see the req.params
object displayed in your browser.
The name of the route parameters must be made up of word characters ([A-Za-z0-9_]).
Let's take it further!
Say you want to have a route path called /users/:name
, where the name of the user is passed into the URL and the application displays the name along with a string. How do you think that can be achieved?
Go ahead and try it out on your own first.
Here is what the route should look like.
router.get('/users/:name', (req, res) => { res.send(`Welcome, ${req.params.name}!`) })
When you visit http://localhost:3000/users/vivian, you should see Welcome, vivian! displayed in the browser.
Let's see how to create a login route in Express. Your login routes require two actions on a single route path. The actions will be differentiated by the route method used. Here is how it will look.
router.get('/login', (req, res) => { res.send('This is should lead to the login form') }) router.post('/login', (req, res) => { res.send('This is used in processing the form') })
After doing this, your store form should have an action whose value is the route defined with the HTTP POST method. Here is how it should look.
<form action="/login" method="POST"> </form>
When the submit button of the form gets clicked, the specified router gets called. The difference between both route paths as stated above is the HTTP POST. This is how the application determines which is responsible for handling the data passed through the form.
Another aspect where this can be experienced is in the area of editing and updating resources.
app.route()
can be used to create a chain of route handlers for a specific route path.
Using the example of the login route, here is how you will make use of app.route()
.
app.route('/login') .get((res, req) => { res.send('This is should lead to the login form') }) .post((res, req) => { res.send('This is used in processing the form') })
You can add more route handlers than we have above.
At this point, you should know how routing works in Express. You have learned how to set up basic routing, and also how to work with route methods and paths. You saw how to make use of route parameters and retrieve values sent via the URL.
If you’re looking for additional JavaScript resources to study or to use in your work, check out what we have available on Envato Market.
With this knowledge, you can go further to build an Express application with complex routing.
Are you a video creator looking to get into influencer marketing? Wondering whether creating sponsored video content is a viable moneymaking option? In this article, you’ll discover insights from new research that reveal how influencer marketing has grown in the last year and how other video creators are planning to pursue relationships with brands. #1: [...]
This post Influencer Marketing: New Research for Video Creators first appeared on .
- Your Guide to the Social Media Jungle
‘Star Trek’ actor Anton Yelchin died last year at the age of 27 when a Jeep pinned him against a gate and brick pillar outside his home. It turns out that his Jeep’s gearshift was poorly designed.
Poor Anton didn’t realise that the Jeep was in neutral when he got out, so it rolled backwards down the driveway, crushing him. This was one of over 100 accidents related to confusion over the gearshift.
Many people thought the Fiat Chrysler gearshift, which looked like most gearshifts, should move up and down to shift into reverse, drive and park. That was their mental model. In other words, their belief about how it should work.
The gearshift, in fact, worked differently than most. It used push-buttons and always returned to the centre position. The fact that the gearshift’s actual functionality – otherwise known as its “conceptual model” – was different than users’ mental models caused issues. Major ones in this instance.
In the field of user experience, we need to understand how users think so we can design with that in mind. When we understand people’s thinking, we can either design to match their current mental models, that is their beliefs about how things should work. Or, we can clearly educate people about anything that might differ from their expectations. We know this is critical to creating usable products.
This article will walk you through how to apply this idea to your own designs, covering:
Let’s get started.
The first step in understanding our users’ mental models is (unsurprisingly) research. Many research techniques such as interviews, observation and focus groups help us understand how users think about the world and products like ours. Let’s look at interviews as an example.
You’ll want to interview several users who have similar characteristics; in other words, those who you think are likely to use your product in a similar way. In an example from my past, my email marketing firm had a lot of users who were small business owners who didn’t have much time for marketing.
Some of our goals for the interviews were:
All of this would teach us about they understood the world of email marketing.
Write down whatever you want to learn and then come up with open-ended questions for your interviews. Start each interview with easy questions to make your participants feel comfortable, then move on to those that require deeper thinking. There are plenty of resources for tips on interviewing users. As a start, take a look at Cameron Rogers’ article right here on UX Mastery, or Steve Portigal’s book, Interviewing Users.
If you’re observing people work or conducting a focus group, it’s still helpful to determine ahead of time what you want to learn, which will help you focus your session.
Once you’ve completed your research, you should have a good idea of common themes, and how they experience your product and other similar products.
When I interviewed small business owners, I learned, for example, that they generally created their newsletters bit by bit because they were interrupted a lot. I also learned they were trying to stay on their customers’ minds, had lots of pain points with our system (things that didn’t work the way they expected or needed them to), and they wanted to feel smart and confident when sending their messages.
By now, you’re starting to form a good understanding of this user group. Your next job is to put this information into a format that will help your designers consider these users’ mindsets. Again, you have several options, including personas, storyboards and mental model mapping. Let’s talk through how to use personas to represent mental models.
In my example, one finding was that the business owners had a mental model based on using Microsoft Word. They thought they could walk away from their work and return to work on it where they left off. In their work as small business owners, they often did need to step away frequently.
Unfortunately, this conflicted with the way our product – or conceptual design – actually worked. If you left for “too long” and the system shut down, you navigated to another page, you lost your work. This caused much pain for users, who were devastated over losing their work. This even happened the usability testing environment test when it wasn’t even their work.
Our persona, Bob the Busy Business Owner, conveyed that there was a mismatch between the persona’s expectation and the software’s reality. The team then needed to decide whether to address this mismatch by meeting Bob’s expectation or by explaining the different model and how the interface worked.
When you create your personas, consider conveying their mental models – their beliefs about how a system will work – in the form of their current work habits, product expectations, issues, and quotes.
One quote that helped describe our Bob persona’s system expectation, for example, was “I need something where I can just plop in my copy and it works.” That helps the team understand that he’s busy, in a hurry, and in need of something that doesn’t require a lot of technical knowledge and fuss. In design discussions, make sure designers keep the personas in mind and address their needs.
Instead of personas, you might decide to create storyboards or maps because you want to represent your users’ mental models more visually, or focus more on illustrating their ideal interactions with your product. That works too.
And now the final step: applying what you know about your users to the design. In this case, it made sense to make the software match Bob’s expectation because he was in a hurry and not technologically advanced. It was important to prevent such critical errors. So that was our strategy.
The designers and developers worked together to create a system that automatically saved users’ work frequently, helping Bob to achieve his goal of feeling confident about his newsletters. To test how well this and other new design changes matched our users’ mental models, we usability-tested each iteration of the design and made modifications where needed.
When you understand how your users think, you can create intuitive designs for them. It just makes sense. If Fiat Chrysler had stuck with designing for a well-established mental model instead of veering in a different direction, the world would be a safer place today.
Up for some further reading? Here are more useful resources on mental models.
Books:
Online Articles:
The post Communicating Mental Models to Your Team appeared first on UX Mastery.