跟随,学习,进步

SitePoint

SitePoint – Learn HTML, CSS, JavaScript, PHP, Ruby & Responsive Design

https://www.sitepoint.com
转到作者网站

How the Top 1% of Candidates Ace Their Job Interviews

You've done it.   You've made it through the initial screening process. You've just earned an interview with one of the most prestigious and successful companies in your industry. As you're waiting in the office with three other candidates, a fourth candidate walks in.   He has an interview scheduled, the same as you.   There's something odd about this interviewee. He already knows everyone there. He's on a first-name basis with the receptionist. Everyone likes him and thinks highly of him. Instead of waiting in the lobby with the rest of you, he's immediately ushered into one of the offices.   Who is this guy?   This is an everyday reality for elite job candidates   How is this possible?   Candidates like these are pretty uncommon. Not because they're so special, but because of their decision-making process. What makes their decision-making process different?   They win coveted jobs and promotions in the face of intense competition They ask for and receive substantially higher salaries than their coworkers Employers create positions specifically for them (to keep them) They earn positions before they're publicly available These job candidates seem to receive preferential treatment wherever they go   Something is going on, but what?   These elite candidates have a very different set of attitudes, behaviors, and habits than most other employees. Is it simply because they're better than everyone else?   Not at all. The post How the Top 1% of Candidates Ace Their Job Interviews appeared first on SitePoint.


9 Key Ways to Turbocharge Your Design Career

This article was created in partnership with StudioWorks. Thank you for supporting the partners who make SitePoint possible. Sure, you need a certain minimal viable level of design skill prowess if you want to have a successful career as a designer. But a lot more than that goes into it, too. Think about how many people you know who can cook amazing food but who would never last five minutes in a restaurant kitchen during the lunch rush. It would be great if we could just sit down, design pretty things, and go home. Or better yet, just chill in our home studios, creating. Unfortunately or not, design is a business just like everything else, and that means you’re going to have to put time, effort, and sometimes money into cultivating the soft skills and business side of your design career. This means managing your time well, marketing yourself, building a brand, experimenting, maybe launching a side business, and generally just putting your name and work out there for people to find. These days, it’s not enough to have a portfolio. That’s just table stakes. You need to plan out your whole career — with the understanding that plans change. Let’s look at some of the things you need to do to develop your career until you’re basically the next Jen Simmons or Jeffrey Zeldman. Get Your Communication Skills Flowing Communication skills come naturally to some, and not so naturally to others. In both cases, those skills are rather drastically affected by the people you have to communicate with most. Most of us find ways to convey our thoughts and intentions clearly to our friends, and also to people in our industry and hobby communities. We learn the lingo, we learn which topics encourage discussion, and which are best avoided. Writing for anyone who’s not a part of your immediate community, and especially writing for people who don’t know what you know, is hard. Speaking to them in person can be harder, depending on how you, as a person, prefer to communicate. But, all the same, you have to. Even if you work in an agency amongst other designers right now, there will inevitably come a time when you have to pitch clients on the benefits of your work, explain to a newbie the processes you use, or defend your decisions to developers who push back, or to other people who just don’t know what you know. If there’s any single thing you take away from this article, focus on your communication skills. It will affect your career more than anything else on this list. If you’re looking for a place to start learning those skills, CopyBlogger always has you covered — at least for the writing side of it. Branch Out into Side Businesses Some side projects are great, strictly because they allow us to get out of our comfort zones, try new things and regain a sense of creative discovery. Others may overlap with the activities you’d use to build a personal brand, which we’ll get into shortly, with the added benefit that they can bring in extra money while you’re establishing yourself as an expert in the field. Here are some of the more popular ways of doing this. 1. Courses Sure, you can throw some tutorials onto your blog, or onto YouTube, for free. And you probably should. But if you want to make a side business out of teaching others what you do, and further your career in the process, you’re going to need an actual product. This is where courses come in. Quality video courses, which are quite popular these days, can be expensive and time-consuming to set up. It’s gotten easier, though, now that you can use all-in-one course development and delivery services like Kajabi. This platform can help you manage everything relating to your premium educational content and running the business around it. You can create membership sites, host live events, create automation funnels, upsells, maintain a blog and manage contacts all in one place, so it’s not as hard as it used to be. However, you still have to get a half-decent camera, a half-decent microphone, and ideally learn some basic video editing skills. This is a side hustle I’d frankly only recommend if you’ve got some time on your hands, and a bit of extra money for some beginner hardware. It can be quite rewarding, though, so don’t dismiss the idea out of hand. 2. Live Streaming I mentioned live events in the last section, so I thought I’d mention streaming as its own thing. Streaming doesn’t have to be educational, although education is probably the best way to sell your expertise. You could just sit there and share designer memes on Twitch if you want. The problem is mostly that the requirements for video and audio haven’t changed, and depending on how you set up your stream schedule, it can be even more demanding than making video courses. Then again, if you don’t mind not making a lot of money, and want to do it for fun, it’s still a great way to “meet” new people, and to be seen. 3. Paid Newsletters Now this is an option I’d save for when you’ve already built a bit of an audience by other means, such as social media and/or blogging. But Substack has made it easier than ever for people to pay writers directly. If you’ve got wisdom to share, and if you think people would be willing to pay to have that wisdom beamed straight into their inboxes, go on and have at it. 4. Make Stuff for Other Designers Plenty of designers and agencies have kept up a healthy “passive” revenue stream by making resources for other designers. Be it a template, a WordPress theme, a Sketch UI kit, an icon font, or whatever else, if it’s valuable to you because it solves problems that you have, then there’s a good chance your peers will be willing to pay for it. Just don’t forget to also give stuff away once in a while. Gratitude goes a long way in the design world. The post 9 Key Ways to Turbocharge Your Design Career appeared first on SitePoint.


SitePoint Premium New Releases: Going Offline + React Native

We're working hard to keep you on the cutting edge of your field with SitePoint Premium. We've got plenty of new books to check out in the library — let us introduce you to them. Going Offline Jeremy Keith introduces you to service workers (and the code behind them) to show you the latest strategies in offline pages. Learn the ins and outs of fetching and caching, enhance your website’s performance, and create an ideal offline experience for every user, no matter their connection. ➤ Read Going Offline. Integrating AdMob in React Native and Expo Google AdMob is one way to install ads into any mobile application in order to monetize it. Installing and configuring AdMob in bare React Native can be a cumbersome process. But it’s relatively simple to install when using a toolchain like Expo — we'll show you how. ➤ Read Integrating AdMob in React Native and Expo. And More to Come… We're releasing new content on SitePoint Premium regularly, so we'll be back next week with the latest updates. And don't forget: if you haven't checked out our offering yet, take our library for a spin. The post SitePoint Premium New Releases: Going Offline + React Native appeared first on SitePoint.


How to Build a Cipher Machine with JavaScript

I was overjoyed recently when I read the news that the British mathematician, Alan Turing will feature on the Bank of England's new £50 note. Turing occupies a special place in the hearts of computer nerds for effectively writing the blueprints for the computer. He also helped to break the notoriously difficult naval Enigma code used by the Nazi U-boats in World War II. In honor of this I decided a quick tutorial to build a cipher machine using the JavaScript skills that are covered in my book JavaScript Novice To Ninja. The cipher we'll be using is the Caesar cipher, named after the Roman emperor, Julius Caesar. It is one of the most simple ciphers there are and simply shifts each letter along a set number of places. For example, the phrase 'Hello World' would become 'KHOOR ZRUOG' using a shift of 3 (which it is the shift that Julius Caesar is thought to have used). You can see an example of the finished code here. Have a play around at writing some secret messages to get a feel for how it works. To get started, fire up your favorite text editor and save the following as caesar.html: The post How to Build a Cipher Machine with JavaScript appeared first on SitePoint.


10 Tools to Help You Manage Your Agile Workflows

This article was created in partnership with monday.com. Thank you for supporting the partners who make SitePoint possible. Software development remains a complex task which balances analysis, planning, budget constraints, coding, testing, deployment, issue fixing, and evaluation. Large projects often fail because no one can comprehend the full extent of requirements from the start. Those requirements then change with each revision of the product. An agile development approach can mitigate the risks. There are many flavors of 'agile', but most rapidly evolve a product over time. Self-organising teams of stakeholders, designers, developers, and testers collaborate to produce a minimum viable product which is extended and revised during a series of iterations - or sprints. Ideally, a fully-working product is available at the end of every sprint. Changing requirements can determine the priorities for the next sprint. Crucial Collaboration Communication distinguishes agile from more traditional waterfall workflows. Teams work together on a particular feature so developers and designers can quickly provide feedback when a requirement becomes impractical or more cost-effective options can be identified. A variety of tools and software is available to help teams collaborate. There are two general options: Separate tools for specific tasks. For example, a feature may be described in a document which is transferred to a to-do list which becomes a pull request and inevitably has bugs reported. All-in-one tools which manage the whole process. The following tools can all help manage your agile workflow. monday.com monday.com has rapidly become the full agile management solution for 80,000 organizations within a few years. monday.com offers a completely customizable application for numerous use-cases such as agile project management. Powerful features include: quick-start project templates (there are over 100 template that are completely customisable to fit your needs) attractive at-a-glance project state dashboards, so you can easily track progress and identify bottlenecks in a "big picture" view intuitive collaboration with team members and clients using @mentions easy file sharing, so you'll always know where your most updated files are multiple views to track progress (reports, Kanban boards, Gantt charts, calendars, timelines etc.) task management, time and deadline tracking automations and integration with other applications to keep everything in one place, so you can focus on the important stuff. Prices start from $25 per month for five users, but a 30 day free trial is available so you can assess the system. The post 10 Tools to Help You Manage Your Agile Workflows appeared first on SitePoint.


What Every Dev Company Needs to Know about NoOps Development

It seems like everything is getting automated these days. And I mean everything. Who would’ve thought that we’d be automating development teams, though? 69% of development companies agree that process and automation improvement is a top priority, so it makes sense we’re heading in this direction. This rise of automation has formed a new development […] The post What Every Dev Company Needs to Know about NoOps Development appeared first on SitePoint.


A Guide to Visual Testing with Percy

This article was created in partnership with Percy. Thank you for supporting the partners who make SitePoint possible. Visual testing is the automated process of ensuring your user interface looks correct in different browsers and at different screen widths. Most development teams rely solely on unit and integration tests. While this practice helps ensure application logic is working correctly, it fails to detect visual defects at the UI level. Implementing this type of test allows visual problems to be detected early and to get fixed before the product is released. In this tutorial, you’ll learn how to set up and run visual testing for your project using Percy. For demonstration purposes, we’ll be using a single-page application that’s API-driven using real-world data. You’ll learn how to visually test UIs that output dynamic data, and about Percy’s visual review and approval workflow. Prerequisites Visual testing is a topic for intermediate and advanced users. To follow this tutorial, you’ll need to be comfortable writing code in JavaScript ES6+ syntax. We won’t be doing actual app development, but you should at least have some experience using the following libraries in case you want to tweak something in the demo project we’ll be using: Express.js + RESTful APIs jQuery Axios CSS frameworks You should also be familiar with Git branching and different types of branching strategies. Familiarity with any testing framework will also help you easily understand the concepts discussed in this article. You’ll need to have a GitHub account before you can proceed with this tutorial. We’ll use this demo project as our starting point. About Percy Percy provides developers with a platform and workflow to run visual testing and reviews on web apps, static sites, or component libraries. There’s a free plan that supports unlimited team members, 5,000 snapshots per month (with a one-month history), and unlimited projects. To get started with Percy, install one of its SDKs into the project you want to visually test. It’s the same as installing a testing framework like Mocha or Jest. Next, you write a script and run it just as you would with any type of test. However, in Percy’s case, DOM snapshots of your web application are captured and uploaded for rendering on Percy’s infrastructure. Percy then detects and highlights visual differences between new and previous snapshots, also known as the baselines. The results are displayed in Percy, where you can review and determine whether the UI looks correct or needs to be fixed. Percy renders each snapshot in Chrome and Firefox and can render at up to ten different screen resolutions. That’s quite impressive, as doing this manually is tiresome. I encourage you to read through the following docs to gain a deeper understanding: The post A Guide to Visual Testing with Percy appeared first on SitePoint.


How to Use Bannersnack to Generate Amazing Banners in Seconds

This article was created in partnership with StudioWorks. Thank you for supporting the partners who make SitePoint possible. Banner ads have been around since the dawn of the Internet. And badly designed banner ads that annoy many users have been around just a long. But 30 years later businesses still pay to put them on websites and in their ad rotation, so they must work when done right. Right? Banner ads, especially animated ones, are being used more than ever on social media profiles and as social ads too, as marketers realize the power of video in catching attention. Today’s banner ads are sophisticated and well designed, and can be highly effective. But for designers, they present a huge challenge. Coding Banner Ads Is Hard and Expensive Banner ads, especially animated ones, are notoriously hard to code in HTML5. Sure, you can create animated banners in Flash, but Apple’s iOS doesn’t support them, and Adobe says they’re shutting down Flash altogether in 2020. GIFs are another possible solution, but they usually have poor resolution and most web users associate GIFs with memes and humor, rather than serious products. So you’re left with HTML5. Coding HTML5 ads — in particular, animated ones — requires expertise, and expertise is expensive. Good coders know their value, and finding one you can trust can be an impossible task. Freelance platforms might seem the obvious place to start, but coders worth their salt soon move away from third-party sites. Fortunately, this is the age of SaaS, and designers can now use applications like Bannersnack with drag-and-drop interfaces that lets you design banner ads quickly and efficiently. What Does Bannersnack Do? Bannersnack is an online app that helps you design fully responsive banner ads for websites and social media platforms — without having any coding or design skills. The Bannersnack creators figured out all the hard coding stuff, so you just log in, choose your size, add your image, select colors and fonts, and get creative. Image source: Bannersnack Let’s take a quick run through the Bannersnack platform and see what it can do. 1. Pick your size Start with a custom size and orientation (vertical, horizontal, and square), or choose a pre-set size. You can even pick a Facebook ad or an Instagram post: Image source: Bannersnack 2. Design your ad You can either design from scratch, or use an existing Bannersnack template. Bannersnack offers static or animated designs in its template gallery, so you can get started even without having a design idea. Image source: Bannersnack 3. Add images and text Customize your design with just a few clicks. If you can use Mailchimp or other SaaS marketing tools, you can use Bannersnack. Edit headlines, text, buttons, background, add your own logos and images, and change design nuances like line heights and transparencies. You can create beautifully designed banner ads that are a perfect match for your existing brand standards and colors. Image source: Bannersnack 4. Animate with ease It’s no secret that animated ads are more engaging and drive action better than static ads. Readers are more likely to react to videos than non-animated content, and more likely to visit the publisher’s page or website. Image source: Impactbnd.com But animation is notoriously tricky. Bannersnack has managed to solve that hurdle — with HTML5 animations that include fade-in, slide-in, and bounces. These aren’t full video ads, but they’ll still pull a user’s eyes towards them on a busy web page and boost your engagement. They have the added advantage of loading quickly — which is vital for preventing mobile users from scrolling past your ad before it’s even loaded. Bannersnack’s HTML5 editor has an intuitive and user-friendly interface and slide management system to make animation simple. Try one of the 32 pre-made animation presets to animate any part of your ad: Screenshot source Or, create custom animations and adjust things like duration, delay, and transitions. The post How to Use Bannersnack to Generate Amazing Banners in Seconds appeared first on SitePoint.


SitePoint Premium New Releases: Responsive CSS + React Native

We're working hard to keep you on the cutting edge of your field with SitePoint Premium. We've got plenty of new books to check out in the library — let us introduce you to them. 14 Essential Responsive CSS Techniques Over 6 easy chapters, we’ll help you to get a grounding in responsive CSS techniques, helping you make your sites and apps look great on any device. Starting with an examination of the em responsive unit and highlight its shortcomings, then move on to the rem unit and how it can overcome them. Finally, we’ll look at how media queries can work with em and rem to provide a complete responsive web design solution. ➤ Read 14 Essential Responsive CSS Techniques. Using Android Native Modules in React Native In this tutorial, we’ll develop a simple application that shows the current battery percentage and charging status. For this, we’ll create a native module with methods to fetch the required information. ➤ Read Using Android Native Modules in React Native. And More to Come… We're releasing new content on SitePoint Premium regularly, so we'll be back next week with the latest updates. And don't forget: if you haven't checked out our offering yet, take our library for a spin. The post SitePoint Premium New Releases: Responsive CSS + React Native appeared first on SitePoint.


How to Create Web Animations with Anime.js

There are many JavaScript animation libraries out there, but Anime.js is one of the best. It's easy to use, has a small and simple API, and offers everything you could want from a modern animation engine. The library has a small file size and supports all modern browsers, including IE/Edge 11+. The only thing that could stop you from using Anime.js right away is its minimal, zen-like documentation. I like the compact, structured, elegant approach it takes, but I think that a more detailed explanation would be helpful. I'll try to fix this issue in this tutorial. Getting Started With Anime.js To get started, download and include the anime.js file in your HTML page: <script src="path/to/anime.min.js"></script> Alternatively, you can use the latest version of the library hosted on a CDN: <script src="https://cdn.jsdelivr.net/npm/animejs@3.0.1/lib/anime.min.js"></script> Now, to create an animation, we use the anime() function, which takes an object as an argument. In that object, we describe all the animation details. let myAnimation = anime({ /* describe the animation details */ }); There are several kinds of properties used to describe the animation. They are grouped into four distinct categories: Targets - this includes a reference to the element(s) we want to animate. It could be a CSS selector (div, #square, .rectangle), DOM node or node list, or plain JavaScript object. There is also an option to use a mix of the above in an array. Properties - this includes all properties and attributes that can be animated when dealing with CSS, JavaScript objects, DOM, and SVG. Property Parameters - this includes property-related parameters like duration, delay, easing, etc. Animation Parameters - this includes animation-related parameters like direction, loop, etc. Let's now see how this applies in practice. Consider the following example: let animation = anime({ targets: 'div', // Properties translateX: 100, borderRadius: 50, // Property Parameters duration: 2000, easing: 'linear', // Animation Parameters direction: 'alternate' }); See the Pen AnimeJS: Basic Example by SitePoint (@SitePoint) on CodePen. Note: I'm not going to cover the HTML and CSS sections of the code in the tutorial. These tend to be easy to grasp without additional explanation. You can find and explore the HTML and CSS in the embedded pens that follow each example. In the above example: We select the green square (the styled div). We move it 100 pixels to the left while transforming it into a circle. We set all this to happen smoothly in two seconds (linear means that no easing will be applied to the animation). By setting the direction property to alternate, we instruct the div element to go back to its initial position and shape after animation completion. Anime.js does that by playing the animation in reverse order. You may notice that I don't use any units when specifying property values. That's because if the original value has a unit, it is automatically added to the animated value. So, we can safely omit the units. But if we want to use a specific unit we must add it intentionally. Let's create something more meaningful. Creating a Pendulum Animation In this example, we will create a pendulum animation. After we "draw" a pendulum using our HTML and CSS skills, it's time to bring it to life: let animation = anime({ targets: '#rod', rotate: [60, -60], // from 60 to -60 degrees duration: 3000, easing: 'easeInOutSine', direction: 'alternate', loop: true }); See the Pen AnimeJS: Pendulum Animation by SitePoint (@SitePoint) on CodePen. In this animation, we use the so-called from-to value type, which defines a range of movement for the animation. In our case, the rod of the pendulum is rotated from 60 to -60 degrees. We also use easeInOutSine easing to simulate the natural motion of pendulum which slows down at peaks and gets faster at the bottom. We use the alternate option again to move the pendulum in both directions and set the loop parameter to true to repeat the movement endlessly. Well done. Let's move to the next example. Creating a Battery Charge Animation In this example, we want to create an animated icon of a charging battery, similar to the icons on our smartphones. This is easily doable with a bit of HTML and CSS. Here is the code for the animation: The post How to Create Web Animations with Anime.js appeared first on SitePoint.


How to Set Up a Vue Development Environment

If you’re going to do any serious amount of work with Vue, it’ll pay dividends in the long run to invest some time in setting up your coding environment. A powerful editor and a few well-chosen tools will make you more productive and ultimately a happier developer. In this post, I’m going to demonstrate how to configure VS Code to work with Vue. I’m going to show how to use ESLint and Prettier to lint and format your code and how to use Vue’s browser tools to take a peek at what’s going on under the hood in a Vue app. When you’ve finished reading, you’ll have a working development environment set up and will be ready to start coding Vue apps like a boss. Let’s get to it! Want to learn Vue.js from the ground up? This article is an extract from our Premium library. Get an entire collection of Vue books covering fundamentals, projects, tips and tools & more with SitePoint Premium. Join now for just $9/month. Installing and Setting Up Your Editor I said that I was going to be using VS Code for this tutorial, but I’m afraid I lied. I’m actually going to be using VSCodium, which is an open-source fork of VS Code without the Microsoft branding, telemetry and licensing. The project is under active development and I’d encourage you to check it out. It doesn’t matter which editor you use to follow along; both are available for Linux, Mac and Windows. You can download the latest release of VSCodium here, or download the latest release of VSCode here and install it in the correct way for your operating system. Throughout the rest of this guide, for the sake of consistency, I’ll refer to the editor as VS Code. Add the Vetur Extension When you fire up the editor, you’ll notice a set of five icons in a toolbar on the left-hand side of the window. If you click the bottom of these icons (the square one), a search bar will open up that enables you to search the VS Code Marketplace. Type “vue” into the search bar and you should see dozens of extensions listed, each claiming to do something slightly different. The post How to Set Up a Vue Development Environment appeared first on SitePoint.


5 Super CSS Grid Generators for Your Layouts

CSS Grid has turned out to be the most exciting evolution of CSS for quite a while. It's a specific CSS tool for building any web layout you can think of, from the simplest to the most complex. Today, CSS Grid is widely supported by all major browsers — it's clear that the dark days of hacking layouts using floats are gone forever. Coding your CSS Grid layout directly in your code editor can be fun. Although the spec is a complex document, the key concepts you would need to build a simple layout don't have a steep learning curve. There are many resources that will get you started in no time, with CSS Master by Tiffany Brown, Rachel Andrew's Grid by Example, and Jen Simmons's Layout Land at the top of the list. For those of you who feel more comfortable coding layouts using a visual editor, there are several interesting online options that you can try out. Here are five CSS online tools with great visual interfaces that I'm going to put through their paces. The idea is: design your CSS Grid-based layouts in a few clicks, grab the code and run with it! Let's put this idea to the test and see what happens. The Test Page Layout In this article, I'm going to provide this simple hand-coded CSS Grid layout. See the Pen responsive CSS Grid example by Maria Antonietta Perna (@antonietta) on CodePen. The layout has more than one HTML container tag working as a Grid container in a nested structure. I could have used the new subgrid feature that's been recently added to Grid, but at the time of writing only Firefox 69+ supports it, and none of the online generators discussed here have implemented this functionality yet. For most of the CSS Grid generators, I'm going to focus my tests only on the <ul> that works as Grid container for the individual cards. This is what the code looks like: .kitties > ul { /* grid styles */ display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); grid-gap: 1rem; } Notice how the value of the grid-template-columns property alone enables you to add responsiveness without media queries by: using the CSS Grid repeat() function together with the auto-fit property. You can add as many columns as you want and they will fit perfectly into the grid's width, whatever that may be. using the minmax() function, which ensures that each column is at least 320px wide, thereby displaying nicely on smaller screens. Most CSS Grid generators don't include the ability to set the grid-template-columns using the CSS Grid features above, so you'll need to adjust the values generated by the tool inside media queries to add responsiveness to your layouts. As I try out the CSS Grid generator tools, I'm going to replace the code above with the code generated by each tool, and examine its capabilities against the results displayed on the screen. The exception will be the fourth CSS Grid generator in the list, a Vue-powered tool by Masaya Kazama. This is because it makes it quite straightforward and quick to build the entire layout, including header and footer, with a few clicks and minor adjustments to one of its preset layouts. Enough talking, let's dive right in! 1. CSS Grid Generator by Sarah Drasner CSS Grid Generator is a shiny new generator coded by Sarah Drasner. The interface is super sleek and you can put together a basic CSS Grid layout in no time. I generated a 2-column grid and dumped the code in my original example. You need media queries to make the layout responsive. Here's the result: See the Pen CSS Grid Generator #1 by Sarah Drasner by Maria Antonietta Perna (@antonietta) on CodePen. The code looks like this: .kitties > ul { /* grid styles */ display: grid; grid-template-columns: 320px 320px; grid-template-rows: 1fr 1fr; /* units for row and column gaps only available in px */ grid-column-gap: 16px; grid-row-gap: 16px; } This tool lets you: set the numbers and units of rows and columns drag within the boxes to place divs within them At the time of writing, Sarah's CSS Grid generator lets you create simple implementations of CSS Grid-based layouts. This is clearly stated by the author: Though this project can get a basic layout started for you, this project is not a comprehensive tour of CSS Grid capabilities. It is a way for you to use CSS Grid features quickly. However, since this is a brand new open-source tool, it's still in active development and the community is invited to contribute. Complex features like minmax() are not implemented yet, but they might find their way into it at a later time. 2. LayoutIt by Leniolabs LayoutIt is quite intuitive and has a few more features than CSS Grid Generator. For example, it lets you set the grid-gap property in px, em and % units, and set grid-template-columns and grid-template-rows using minmax(). However, this is not enough to ensure responsiveness, so you'll still need to adjust your values using media queries. Also, I found no way of setting the grid-gap property, so you'll have to do it manually if you'd like some white space in between rows and columns. Here's the result as I entered the generated code into my original example: See the Pen CSS Grid Generator #2 by Leniolabs by Maria Antonietta Perna (@antonietta) on CodePen. Below is what the relevant code looks like: .kitties > ul { /* grid styles */ display: grid; grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr); grid-template-rows: 1fr 1fr; /* grid gap not in code repeat, auto-fit, and auto-fill not there */ } 3. Griddy by Drew Minns With Griddy you can set the number of columns and rows using fr, px, % and auto units, but there's no minmax() function. You can add gaps to your columns and rows using both px and % and set justify-items and align-items properties to align items within the grid. You'll need media queries for responsiveness. Below is what the generated code displays on the screen: See the Pen CSS Grid Generator #3 by Drew Minns by Maria Antonietta Perna (@antonietta) on CodePen. Here's the generated code in place on the original demo: The post 5 Super CSS Grid Generators for Your Layouts appeared first on SitePoint.


Mobile Attribution 101: What Every Developer Needs to Know

This article was created in partnership with StudioWorks. Thank you for supporting the partners who make SitePoint possible. Optimizing the user experience of your app is crucial for its success, and the best way to do so is by collecting data on how users interact with it. While regular analytic tools do a good job, there’s an even better way now. Welcome to mobile attribution. This approach to measuring app performance allows you to discover where and how users are interacting with your app and connect them with key points in the app journey. But what exactly is mobile attribution and how do you use it? Keep reading to learn. Mobile Attribution Explained Mobile attribution is the process of measuring two metrics, such as ad spend and app installs. Given that the mobile advertising industry will exceed $244 billion by 2020, you need to know which strategies and channels are wasting your money or generating the most returns. Mobile attribution also helps mobile app developers and companies determine how users are interacting with apps and mobile ads. This information can then be used to optimize marketing campaigns, the user experience of an app, and more. In a nutshell, the process looks like this: How mobile attribution works Not taking advantage of mobile attribution means that you won’t have the most detailed and accurate data on your mobile app and its advertising performance. This can result in missing opportunities when they arise, or discovering problems too late. Appsflyer is a market leader in ad attribution and analytics with their proprietary “People-based Attribution” technology Next, let’s talk more about why you should be using mobile attribution. The Benefits of Mobile Attribution These are some of the main benefits you will experience by taking advantage of mobile attribution. Track user events to optimize your app You will be able to track every little detail of how users interact with mobile ad campaigns in your app. This includes where they found your app originally, which pages they navigate to, and what features they interact with the most. This information is priceless. It’s telling you exactly what pages and features users enjoy the most, which channels drive the most traffic, and what campaigns are generating the most results for your app. You can then invest more capital into profitable channels, push favorite features to the forefront, and improve how every user engages with your application. The post Mobile Attribution 101: What Every Developer Needs to Know appeared first on SitePoint.


SitePoint Premium New Releases: Smashing 6 + GraphQL & React Native

We're working hard to keep you on the cutting edge of your field with SitePoint Premium. We've got plenty of new books to check out in the library — let us introduce you to them. Smashing Book 6: New Frontiers In Web Design It’s about time to finally make sense of all the front-end and UX madness. Meet Smashing Book 6, with everything you need to know about web design. From design systems to accessible single-page apps, CSS Custom Properties, CSS Grid, Service Workers, performance patterns, AR/VR, conversational UIs and responsive art direction. ➤ Read Smashing Book 6: New Frontiers In Web Design. Working with GraphQL and React Native In this tutorial, we’re going to demostrate the power of GraphQL in a React Native setting by creating a simple coffee bean comparison app. So that you can focus on all of the great things GraphQL has to offer, Jamie has put together the base template for the application using Expo. ➤ Read Working with GraphQL and React Native. And More to Come… We're releasing new content on SitePoint Premium regularly, so we'll be back next week with the latest updates. And don't forget: if you haven't checked out our offering yet, take our library for a spin. The post SitePoint Premium New Releases: Smashing 6 + GraphQL & React Native appeared first on SitePoint.


Master Modern JavaScript with This Curated Reading List

Are you daunted by the complexity of the JavaScript ecosystem? Are you still writing ES5, but looking for an opportunity to embrace modern standards? Or, are you confused by the explosion of frameworks and build tools, and unsure what to learn first? Fear not, here are my handpicked selection of books from SitePoint Premium, intended to help you well on your way to mastering modern JavaScript. JavaScript: Novice to Ninja, Second Edition I've placed this book at the top of my list, as it has something for almost everybody. It starts by covering the fundamentals (and thus serves well as a desk reference), then moves on to tackle more advanced topics, such as testing and functional programming. The second edition has been updated to cover ECMAScript 6 and does a great job of introducing you to its more common features. You also get to put your newly acquired knowledge into practice at the end of each chapter, as you build out a quiz app, adding features as you move through the book. I really like this project-based approach to learning and think it is one of the better ways to advance your programming skills. For those who just want to dip, I'd recommend reading the Modern JavaScript Development chapter. This will bring you up-to-date with many of the recent developments, such as working with modules, and the hows and the whys of transpiling your code. ➤ Read the book Practical ES6 This anthology picks up where Novice to Ninja left off and allows you to dive deeper into many of the newer additions to the JavaScript language. It covers much of the basic syntax (e.g. const, let, arrow functions, etc...), and offers a great way to get up to speed in a particular area. There are also more in-depth articles on topics such as ES6 classes and ES6 modules, as well as a look at what came down the pipeline in ES2017 and ES2018. And if you're starting to get confused about what all these version numbers mean, we've got you covered. The anthology packs a chapter on JavaScript versioning and the process of deciding what gets added to the language. ➤ Read the book A Beginner's Guide to npm - the Node Package Manager npm is a package manager for JavaScript, similar to PHP's composer, or Perl's CPAN. It allows you to search an online database of packages (a.k.a. the registry) and install them on your machine. The npm registry is vast — containing over 600,000 packages — and I think it is fair to say that it has revolutionized the way JavaScript developers collaborate with each other. This short book from our Developer Essentials series has made the list because npm is something you cannot ignore if you are serious about writing JavaScript in 2019. The guide walks you through getting npm installed and configured (which can sometimes be a tad tricky) and using it effectively in your day-to-day work. If you're going to learn just one JavaScript tool in 2019, make it npm. You'll encounter it in tutorials everywhere and it is the standard delivery mechanism for almost any modern JavaScript library out there. ➤ Read the book JavaScript: Best Practice Now that we've had a look at the basics, it's time to kick it up a notch with some JavaScript best practices. This anthology is full of tips and tricks to help you write modern JavaScript that is performant, maintainable, and reusable. It's hard to pick favorites from so many great titles, but there are two articles that stand out. The Anatomy of a Modern JavaScript Application takes a good look at how to build a JavaScript application in 2019. It covers everything from application architecture to deployment and will help you to order many of the concepts and buzzwords you may have heard floating about. Flow Control in Modern JavaScript introduces you to a variety of strategies for dealing with asynchronous JavaScript in a modern code base. It looks at one of my favorite additions to the language — async await — and dispels the myth that writing a JavaScript web app will automatically land you in callback hell. ➤ Read the book Node.js Web Development, Fourth Edition No journey through modern JavaScript would be complete without a look at how to run it on the server. And this book gives you an excellent starting point, bringing you straight to the heart of developing web applications with Node.js. As you follow along you'll build and iterate on a note taking app. This will form the basis for learning all about real-time applications, data storage, user authentication, deployment with Docker and much more. And even if server-side development isn't your thing, I'd still recommend reading the first couple of chapters. These will give you a good idea where Node fits in to today's JavaScript landscape. ➤ Read the book The Versioning Guide to Modern JavaScript To finish we have The Versioning Guide to Modern JavaScript, which is really a large collection of links taken from the much-missed Versioning newsletter. I've included this, as there's so much going on in the world of modern JavaScript development, that I've barely been able to scratch the surface here. I'm confident that this guide will offer you a wealth of ideas and inspiration on what to dig into next. ➤ Read the book And that's a wrap. I hope this curated list goes some way to helping you navigate the choppy waters of modern JavaScript development. The post Master Modern JavaScript with This Curated Reading List appeared first on SitePoint.


An Introduction to Data Visualization with Vue and D3.js

Web applications are normally data-driven and oftentimes the need arises to visualize this data. That’s where charts and graphs come in. They make it easier to convey information, as well as demonstrate correlations or statistical relationships. Information presented in the form of a chart or a graph is also easier for a non-native speaker to understand. In this tutorial, we’ll learn how to visualize data in a Vue project. For this, we’ll be using the popular D3.js library, which combines powerful visualization components and a data-driven approach to DOM manipulation. Let’s get started. Note: the code for this tutorial can be found on GitHub. What is D3? As you can read on the project’s home page, D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG, and CSS. Its emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework. Whereas most people will refer to D3.js as a data visualization library, it’s not. D3 is more of a framework comprising different parts — such as jQuery parts (which help us select and manipulate DOM elements), Lodash parts, animation parts, data analysis parts, and data visualization parts. In this tutorial, we’ll be working with the visualization aspect of D3. The real meat of D3 when visualizing data is: the availability of functions for decorating data with drawing instructions creating new drawable data from source data generating SVG paths creating data visualization elements (like an axis) in the DOM from your data and methods What We’ll Be Building We want to create an app that lets users search for a repo on GitHub, then get a visual representation of issues opened in the past week that are still open. The end result will look like this: Prerequisites This tutorial assumes you have a working knowledge of Vue. Previous knowledge of D3.js isn’t required, but if you’d like to get up to speed quickly, you might want to read our D3 by example tutorial. You’ll also need to have Node installed on your system. You can do this by downloading the binaries for your system from the official website, or using a version manager. Finally, we’ll be using the following packages to build our app: Vue CLI — to scaffold out the project D3.js — to visualize our data Lodash — which provides a handful of utility methods Moment JS — for date and time formatting axios — an HTTP client to help us make requests to an external API New Vue Project I prefer creating new Vue projects using Vue CLI. (If you’re not familiar with Vue CLI, our beginner’s guide in this Vue series gives a full introduction.) Vue CLI provides a nice folder structure for placing different sections of the code, such as styles, components, and so on. Make sure that the CLI is installed on your machine: npm install -g @vue/cli Then create a new project with the following command: vue create issues-visualization Note: while creating a new project using Vue CLI, you’ll be prompted to pick a preset. For this particular project, we’ll just stick with the default (Babel + ESLint). Once our new Vue project has been created, we cd into the project folder and add the various node modules we’ll need: npm install lodash d3 axios moment Even though this is a simple app that doesn’t have many running parts, we’ll still take the components approach instead of dumping all the code inside the App.vue file. We’re going to have two components, the App component and a Chart component that we’re yet to create. The App component will handle fetching data from GitHub, then pass this data to the Chart component as props. The actual drawing of the chart will happen inside the Chart component. Structuring things this way has the advantage that, if you want to use a library other than axios to fetch the data, it’ll be easier to swap it out. Also, if you want to swap D3 for a different charting library, that’ll be easier too. Building the Search Interface We’ll start by building a search interface that lets users enter the name of the repo they want to see visualized. In src/App.vue, get rid of everything inside the <template> tag and replace the content with this: <template> <div id="app"> <form action="#" @submit.prevent="getIssues"> <div class="form-group"> <input type="text" placeholder="owner/repo Name" v-model="repository" class="col-md-2 col-md-offset-5" > </div> </form> </div> </template> Here we have a form which, upon submission, prevents the browser’s default submission action, then calls a getIssues method that we’re yet to define. We’re also using a v-model directive to bind the input from the form to a repository property inside the data model of our Vue instance. Let’s declare that property repository as an empty string. We’ll also add a startDate property, which we’ll later use as the first date in our time range: import moment from "moment"; import axios from "axios"; export default { name: "app", data() { return { issues: [], repository: "", startDate: null }; }, methods: { getIssues() { // code goes in here } } }; Now on to creating the getIssues method: getIssues() { this.startDate = moment() .subtract(6, "days") .format("YYYY-MM-DD"); axios .get( `https://api.github.com/search/issues?q=repo:${this.repository}+is:issue+is:open+created:>=${this.startDate}`, { params: { per_page: 100 } } ) .then(response => { const payload = this.getDateRange(); response.data.items.forEach(item => { const key = moment(item.created_at).format("MMM Do YY"); const obj = payload.filter(o => o.day === key)[0]; obj.issues += 1; }); this.issues = payload; console.log(this.issues); }); } In the above block of code, we start by setting the startDate data property to six days ago and formatting it for use with the GitHub API. We then use axios to make an API request to GitHub to get all issues for a particular repository that were opened in the past week and that are still open. You can refer to GitHub’s search API if you need more examples on how to come up with query string parameters. When making the HTTP request, we set the results count to 100 per page (the max possible). There are hardly any repositories with over 100 new issues per week, so this should be fine for our purposes. By default, the per_page value is 30. If the request completes successfully, we use a custom getDateRange method to initialize a payload variable that we will be able to pass to the Chart component. This payload is an array of objects that will like so: [ {day: "Dec 7th 18", issues: 0}, {day: "Dec 8th 18", issues: 0}, {day: "Dec 9th 18", issues: 0}, {day: "Dec 10th 18", issues: 0}, {day: "Dec 11th 18", issues: 0}, {day: "Dec 12th 18", issues: 0}, {day: "Dec 13th 18", issues: 0} ] After that, we iterate over the API’s response. The data we’re interested in is in an items key on a data property on the response object. From this, we take the created_at key (which is a timestamp) and format it as the day property in our objects above. From there, we then look up the corresponding date in the payload array and increment the issues count for that date by one. Finally, we assign the payload array to our issues data property and log the response. Next, let’s add in the getDateRange method: methods: { getDateRange() { const startDate = moment().subtract(6, 'days'); const endDate = moment(); const dates = []; while (startDate.isSameOrBefore(endDate)) { dates.push({ day: startDate.format('MMM Do YY'), issues: 0 }); startDate.add(1, 'days'); } return dates; }, getIssues() { ... } } Before we get to the visualization bit, let’s also log any errors we might encounter when making our request to the console (for debugging purposes): axios .get( ...) .then(response => { ... }) .catch(error => { console.error(error); }); We’ll add some UX for informing the user in the case that something went wrong later. So far, we have an input field that lets the user enter the organization/repository name they wish to search issues for. Upon form submission, all issues opened in the past one week are logged to the console. Below is an example of what was logged on the console for the facebook/react repo: If you start up the Vue dev server using npm run serve and enter some different repos, you should see something similar. If you’re stuck for inspiration, check out GitHub’s Trending page. Next comes the fun bit — visualizing this data. Drawing a Bar Chart Using D3 Earlier on, we mentioned that all the drawing will be handled inside a Chart component. Let’s create the component: touch src/components/Chart.vue D3 works on SVG elements, and for us to draw anything with D3, we need to have an SVG element on the page. In our newly created component (src/components/Chart.vue), let’s create an SVG tag: <template> <div> <svg></svg> </div> </template> For this particular tutorial, we’ll visualize our data using a bar chart. I picked a bar chart because it represents a low complexity visual element while it teaches the basic application of D3.js itself. The bar chart is also a good intro to the most important D3 concepts, while still having fun! Before proceeding, let’s update our App component to include the newly created Chart component below the form: <template> <div id="app"> <form action="#" @submit.prevent="getIssues"> ... </form> <chart :issues="issues"></chart> </div> </template> Let’s also register it as a component: import Chart from './components/Chart.vue'; export default { name: "app", components: { Chart }, ... } Notice how we’re passing the value of the issues data property to the Chart component as a prop: <chart :issues="issues"></chart> Let’s now update our Chart component to make use of that data: <script> import * as d3 from "d3"; import _ from "lodash"; export default { props: ["issues"], data() { return { chart: null }; }, watch: { issues(val) { if (this.chart != null) this.chart.remove(); this.renderChart(val); } }, methods: { renderChart(issues_val) { // Chart will be drawn here } } }; </script> In the above code block, we’re importing D3 and Lodash. We then instantiate a chart data property as null. We’ll assign a value to this when we start drawing later on. Since we want to draw the chart every time the value of issues changes, we’ve created a watcher for issues. Each time this value changes, we’ll destroy the old chart and then draw a new chart. Drawing will happen inside the renderChart method. Let’s start fleshing that out: renderChart(issues_val) { const margin = 60; const svg_width = 1000; const svg_height = 600; const chart_width = 1000 - 2 * margin; const chart_height = 600 - 2 * margin; const svg = d3 .select("svg") .attr("width", svg_width) .attr("height", svg_height); } Here, we set the height and width of the SVG element we just created. The margin attribute is what we’ll use to give our chart some padding. D3 comes with DOM selection and manipulation capabilities. Throughout the tutorial, you’ll see lot’s of d3.select and d3.selectAll statements. The difference is that select will return the first matching element while selectAll returns all matching elements. The post An Introduction to Data Visualization with Vue and D3.js appeared first on SitePoint.


The Strategic Advantages of Headless Web Design

This article was created in partnership with Duda. Thank you for supporting the partners who make SitePoint possible. Kentico’s most recent State of the Headless CMS report claims that the concept of the headless content management system is “becoming the industry standard for future-proofing and streamlining content creation.” In fact, the report estimates that by this summer, headless CMS use will have doubled. But what does that even mean? If you’re currently using a traditional CMS such as WordPress, Drupal or Joomla for your web development needs, chances are you may have never heard of a headless CMS. But what you might know is that you want to build a one-of-a-kind website for your growing agency that can scale with ease, and that marketing your brand across multiple channels is a must if you want to beat the competition. In this article, we’re going to share with you what the headless CMS trend is all about and how using this API-powered approach to design and deploy your company’s website can help you get ahead, no matter how competitive your industry is. So, let’s get started. What Is a Headless CMS? To better understand what a headless CMS is, let’s compare a traditional CMS (or “monolithic”, as developer Bret Cameron likes to call it), a decoupled CMS, and a headless CMS. Image source Traditional CMS Traditional CMS platforms like WordPress link the front end of your website, called the head, to the back end of your site, where all your content files and databases are stored. The head of the CMS is strictly responsible for presenting your website to site visitors when they click on your site. The back end, on the other hand, not only stores content, but is where website design and customization applications are stored, where content is created, and where management of site functionality occurs. Paired together, as they traditionally are, the back-end portion of the website relies on the head of the CMS to display the stored content on devices to users. Decoupled CMS With a decoupled CMS architecture, the head portion and the back end of the site are split into two separate systems. One system is responsible for content creation and storage, and the other is responsible for presenting the data to users on an interface, such as a website, mobile app, smartwatch, etc. When content is created on your website using a headless CMS, a RESTful API helps connect the back end to the head, so that the content can be delivered to users on any device or channel with ease. A RESTful API is a type of application interface using HTTP requests to GET, POST, PUT, and DELETE data that’s requested by users. It allows for multiple data formats such as JSON, HTML, XML, and plain text. It’s ultimately what links the client and server in a decoupled CMS, allowing your site to infinitely scale and deliver content to anyone on any device. Headless CMS A truly headless CMS eliminates the head portion altogether, leaving just the back end. In other words, there’s no dedicated system for front-end presentation. And while you might initially wonder if this type of structure might be to your disadvantage, it’s actually the best way to display content to your site visitors on all devices and interfaces, putting your agency in the best possible position to scale. Here’s a simple breakdown of how it works: Website owners create content (often in small blocks) in the headless CMS, with no regard for how it will display to users. They also store and manage this content here. An API connects the back end to many different channels and the various engines that power their front ends. The channel or device displays your site’s content. The way your content will display on the different channels and devices will depend on the frameworks and tools your front-end developers use to act as the “head” portion of your headless CMS. So it’s more freedom to integrate with more front ends, more scalably and without the risk of breaking anything. How, exactly? Let’s dive a little deeper. The Advantages of a Headless CMS APIs work with a headless CMS to do the following: Reduce Strain. Using a headless CMS, which stores content in a cloud repository as opposed to a server, will leverage less bandwidth, save resources, and reduce the strain your clients’ websites experience.
 Manage and Store Content
.
With a headless CMS, all content, including written text and images, are stored in the back end of the database. With a traditional CMS, not only is content stored and managed here, but so are front-end templates, CSS, and plugins for front-end functionality. Separating the back end from the front end means you can upgrade and customize your website without compromising site speed or performance — since all your client needs to worry about is managing and storing content. Third-party Integrations.

A headless CMS gives you the chance to use third-party systems to trigger, write and read content for you, making development less disruptive. It also gives developers the flexibility to use the front-end framework they prefer to display their site content, focusing more on content creation and less on content management. Lastly, a headless CMS protects you, your company and your website’s content from future technological advances. After all, platforms and technology are always evolving, making it challenging to keep up. For example, think about all the problems that those of us who didn’t build responsive websites had when mobile-friendliness became a necessity. People all over, regardless of how well-established and successful they were at the time, had to change everything to ensure a seamless mobile experience. And there’s no end in sight to the trends — from artificial intelligence to augmented reality to voice assistants — that have the power to change the way you build and deliver digital content experiences. Traditional CMS platforms were designed with website publishing in mind. They were not built with social media product listings, smartwatch apps or talking speakers in mind. So when the build is decoupled from the delivery, you’re in the best possible position to experiment with new channels and formats on an agile basis. And this is a key aspect to any agency’s value proposition. If you take advantage of the headless CMS approach and use APIs to deliver your content to where it needs to surface, it won’t matter what changes. That’s because as long as an API-fed front end can be built, your client’s content can be configured to render properly. Headless CMS Limitations Though it might seem as though a headless CMS is the answer to all your website problems, be aware that there are some downsides preventing traditional CMS users from making the switch: Limited Editing UI.

When compared to traditional CMSs, headless CMSs usually lack the flexibility that content managers generally rely on to optimize the content for specific front end uses. If you need to use your CMS for creating landing pages or even article page layouts, the lack of a “Preview” button might be an issue. There is no WYSIWYG page editor on these platforms, since the whole point of going headless is that it won’t render HTML, which makes designing medium-specific content experiences more difficult.
 Lack of Built-in Features
.
 Boris Kraft, CTO and co-founder of Magnolia CMS, reminds people that a traditional CMS will generally come with features like “asset management, navigation, security, workflow, access control, caching, categorization and link management.” In fact, he goes on to say that while a headless CMS does provide companies with more flexibility, many often get lost in the hype and forget that “I have to write, debug and maintain everything I need myself” with a headless CMS solution. While there is no CMS solution that satisfies all needs, it’s worth noting that the headless CMS approach can be beneficial when used in a hybrid situation. In fact, if you use a solution such as Duda, a leading web design platform for companies providing web design services to others, and take advantage of APIs to deliver content and handle your site’s structure and layouts on multiple channels, you can get the best of both worlds. The post The Strategic Advantages of Headless Web Design appeared first on SitePoint.


SitePoint Premium New Releases: React + React Native

We're working hard to keep you on the cutting edge of your field with SitePoint Premium. We've got plenty of new books to check out in the library — let us introduce you to them. Get Started with React Native For developers with a web background, frameworks such React Native allow you to create mobile apps with languages you’re already familiar with: HTML, XML, CSS, and JavaScript. This guide will help get you up and running with React Native. ➤ Read Get Started with React Native. Build Your Own React Universal Blog App An introductory course to building your first universal React app. Starting with an introduction to React, and then getting familiar with the invaluable React toolkit - Create React App, we'll then walk you through the steps of creating a universal React blog app from scratch. ➤ Read Build Your Own React Universal Blog App. And More to Come… We're releasing new content on SitePoint Premium almost every day, so we'll be back next week with the latest updates. And don't forget: if you haven't checked out our offering yet, take our library for a spin. The post SitePoint Premium New Releases: React + React Native appeared first on SitePoint.


A Beginner’s Guide to Feathers.js

In this article, you’ll learn how to build a RESTful API Server in Node.js using Feathers. An API server, also known as an Application Server, is a program that provides data to front-end applications. It also handles business logic in the back end and provides restricted access to an organization's database. It doesn't just prevent unauthorized persons from accessing the data; it can also restrict logged-in users from accessing or altering data if they don't have permission to do so. Every application you build will need to provide a service to its end users. For that, your application will need data to process. You can use remote APIs to create a new service. For most applications, though, you’ll need to manage your own data store. A popular option is to use online data storage services such as Firebase. This way, you don't have to deal with the nitty gritty details of running a distributed database server. However, your project needs may require the use of a full-fledged, in-house database management system such as MongoDB or Oracle. For your front-end application to access the data stored in the database, you’ll need a server application that sits between the database and the front-end application. As illustrated in the diagram above, the work of an application server is to access data from a database using SQL or NoSQL commands and convert into a format that front-end applications (client browser) can understand — such as JSON. In addition, the application server can use various security protocols — such as HTTPS encryption and token authorization — to ensure that communication between the database and the client application is safe and secure. One main advantage of using such an architecture is that you can deploy applications that target different platforms — desktop, mobile, web, and so on — using the same application server. It’s also very easy to scale your application horizontally in order to serve more users efficiently with fast response times. We’re going to build a simple API server and demonstrate the various features that Feathers provides. Prerequisites Before you begin following this tutorial, you’ll need to have a good foundation in the following topics: ES6 JavaScript creating Express apps creating RESTful APIs with Express Feathers is built on top of Express, a minimalist web framework for Node.js. If you’ve completed the tutorials demonstrated in the links, you’ll realize that it's quite tiring building RESTful APIs using just Express. With Feathers, most of the repetitive work is already done for you. You only need to focus on configuring and customizing code. Let's dive into the code and learn how this web framework works. Project Creation To get started with Feathers, you’ll need to install its command line application globally: npm install -g @feathersjs/cli Next, create a new API project using the commands below: mkdir contacts-api cd contacts-api feathers generate app Below are the options I chose. Feel free to choose any testing framework. Unfortunately, testing is beyond the focus of this article, so it won't be covered here. Personally, I like simplicity, and that’s why I went with Jest. Once the installation is complete, you can open you favorite code editor to look at the project files. If you’ve completed the Express tutorials I listed in the prerequisites section, you shouldn't be intimidated by the generated code. Here's a brief summary that describes the folders and files. Don't be too concerned with what each file does right now. You’ll come to understand how they work in the course in this tutorial. For now, let's confirm that the tests are working. Linting To ensure our project is compliant with the defined ESLint rules, just run the command npm test. If you’re on a Unix or Linux platform, this should run fine. If you’re on Windows, there are few things you need to adjust for the tests to run successfully. First, go to package.json and look at the scripts section. Change the test line to this: "scripts": { "test": "npm run eslint && SET NODE_ENV= npm run jest", }, Next, if you’ve installed Prettier in Visual Studio Code, you'll need to change the single quote setting to true in the Workspace settings tab: { "prettier.singleQuote": true } Finally, make sure that, when you create or edit any file, the line ending is LF. If you’re using Visual Studio Code or a similar editor, you can check the current line ending style at the status bar. If it says CRLF, change to LF. Making those changes will help you pass the lint tests. Unfortunately, to make the tests pass will require a bit more work, which won't be covered here. Let's look at how we can generate a CRUD RESTful interface. Generate Service Building a Restful CRUD API interface in Express requires a bit of work. In Feathers, all you have to do is execute a single command, answer a few questions and have the code generated for you: $ feathers generate service ? What kind of service is it? NeDB ? What is the name of the service? contacts ? Which path should the service be registered on? /contacts ? What is the database connection string? nedb://../data force config\default.json create src\services\contacts\contacts.service.js force src\services\index.js create src\models\contacts.model.js create src\services\contacts\contacts.hooks.js create test\services\contacts.test.js We’ll be using NeDB database for this tutorial. Feathers does support both SQL databases such as MySQL and NoSQL databases such as MongoDB. However, installing a database system — whether on your machine or on a cloud server — requires a certain amount of time configuring it. NeDB, on the other hand, is an in-memory database that’s 100% JavaScript and supports a subset of MongoDB API. There’s no configuration needed; you just install it. It's a great database for prototyping and testing new applications. This is what we’ll use in this tutorial. Let's briefly look at some of the files that have been generated using this command: services/contacts/contact.service.js. This is a Feathers service that provides the CRUD API endpoints for /contacts. Pretty small, isn't it? This is because Feathers does the heavy lifting for us. It saves us from writing boilerplate CRUD code. services/contacts/contact.hooks.js. This is where we customize how the CRUD logic behaves. We have the before section, where we can check or change data before Feathers reads or writes to the database. We also have an after section, where we can check or change the results from the database before it’s sent to the client application. We can do things like restricting access, data validation, performing join operations and calculating values for additional fields or columns. models/contacts.model.js. This where we define a model and attach it to a database table. This is also where we define a schema which can be used to validate fields when a new record is inserted or updated. Unfortunately, NeDB doesn’t support schemas. However, I've provided an example of a model that’s connected to MongoDB, which supports the schema feature via the mongoose adapter: "use strict"; const mongoose = require("mongoose"); const Schema = mongoose.Schema; require("mongoose-type-email"); const contactsSchema = new Schema({ name: { first: { type: String, required: [true, "First Name is required"] }, last: { type: String, required: false } }, email: { type: mongoose.SchemaTypes.Email, required: [true, "Email is required"] }, phone: { type: String, required: [true, "Phone is required"], validate: { validator: function(v) { return /^\+(?:[0-9] ?){6,14}[0-9]$/.test(v); }, message: "{VALUE} is not a valid international phone number!" } }, createdAt: { type: Date, default: Date.now }, updatedAt: { type: Date, default: Date.now } }); const contactsModel = mongoose.model("contacts", contactsSchema); module.exports = contactsModel; Despite the limitations of using NeDB, it’s still a great database for prototyping. Most NoSQL databases will allow you to submit data using any structure without having to define a schema first. It’s wiser to implement a schema once the project requirements have been realized. With a schema in place, Feathers will perform field validation for you using the rules you’ve defined. You'll need a production-ready database such as MongoDB to be able to define a schema. Do note the configuration for the development database is defined at config/default.json: "nedb": "../data" This is where database credentials are provided. We also have another config file called config/production.json. This is the production database configuration that’s used when you deploy your Feathers app. It's important to use a separate database during development. Otherwise, you run the risk of deleting or corrupting business operational data on the production database. Now that we have our CRUD service for contacts set up, it's time to take it for a spin. You can start the Feather server using the command npm start. Do note that this server doesn’t support hot reloading. So you'll need to restart it every time you make a change to the code. In order to interact with our Feathers app, we’ll need an API browser tool such as Postman or Insomnia. I'll be using Insomnia in this tutorial, but you can follow along easily with Postman or any other tool. Create a new GET request (press Ctrl + N) and give it the title “List Contacts”. In the URL section, enter http://localhost:3030/contacts. When you hit the Send button, you should have the following view: Nothing! Our database is currently empty, so we need to create some new contacts. Create a new request called Create Contact. Fill in the rest of the fields as shown below: In case you forgot to change the METHOD to POST in the above form, you can do so later. Change the method to POST and change the Body tab to JSON. Copy the following data in the JSON tab: { "name": { "first": "Jack", "last": "Bauer" }, "email": "jack@ctu.mail", "phone": "+1234567" } When you hit the Send button, you should get the following response. Notice that an _id has been generated for your new contact. Go back to List Contacts and hit the Send button again. You should get the following result: { "total": 1, "limit": 10, "skip": 0, "data": [ { "name": { "first": "Jack", "last": "Bauer" }, "email": "jack@ctu.mail", "phone": "+1234567", "_id": "ybnRxL6s2QEGhj4i" } ] } Go back to Create Contact and post a couple of new records: { "name": { "first": "Chloe", "last": "O'Brian" }, "email": "chloe@ctu.mail", "phone": "+1987654" } { "name": { "first": "Renee", "last": "Walker" }, "email": "renee@fbi.mail", "phone": "+150505050" } Let's now perform an update. For this, we won't use the UPDATE HTTP method. This method will completely overwrite a record. What we want to do is just overwrite a single field, not the the whole record. For that, we’ll use PATCH. Create a new request, Update Contact as illustrated below: In the URL field, put http://localhost:3030/contacts/{_id}. Replace {_id} with the ID of the first record. Place the following data into the JSON tab: { "email": "jack.bauer@gmail.com" } Hit the Send button. You should get the following result: Notice how the the rest of the fields remain intact. Next, we’re going to delete a record. This one is easy. Just create a new DELETE request and name it Delete Contact. In the URL field, use the format http://localhost:3030/contacts/{_id}. Just like before, replace {_id} with the ID of the record you want to delete. Hitting Send will delete that record for you. You can confirm by running the List Contact request again. We've just verified that all CRUD operations are running okay. In the next section, we’ll learn how to set up authentication. The post A Beginner’s Guide to Feathers.js appeared first on SitePoint.


The Best Web Hosting Providers For Your Needs

In this article, we're going to dive into the offerings of the most prominent players in the hosting industry, and wade through their plans, infrastructure, and reputation among users, to give you recommendations for the best hosting provider for your needs. We divided hosting vendors into three categories: general-purpose shared hosting providers WordPress — specialized premium providers, and unmanaged, dedicated server solutions General-purpose Shared Hosting Providers This category covers the widest part of the hosting market — from the entry-level shared plans to prosumer and premium offerings with dedicated resources and different levels of support. A2 Hosting A2 Hosting was founded in 2003 in Michigan, USA. They offer entry-level shared hosting packages, managed VPS and dedicated servers and seller hosting. Their shared packages are standard cPanel packages, with SSD-based storage and a promise of reserved CPU and RAM resources — even with the smallest of plans. Their LITE plan begins at $2.96 per month, which allows for one website. Their SWIFT plan has unlimited websites, starting with $3.70 per month. And their TURBO plan starts at $7.03 per month. These prices are — as the A2 website claims — a 63% discount. They offer free migration, 24/7 support, DDOS protection and “99.99% uptime commitment”, which is always nice to know. The flagship plan that distinguishes A2 is the TURBO package, which uses LiteSpeed servers — an excellent replacement for Apache, which also brings with it a performance edge. Underlying LiteSpeed allows A2 to offer QUIC as an experimental feature on the TURBO plan. A2 offers four possible server locations — two data centers in the US, one in Singapore and one in Amsterdam, so they'll have you covered in most parts of the world. For more details check out their website. SiteGround SiteGround is a “holding of companies registered in the USA, UK, Bulgaria, and Spain that manages four offices and several datacenter locations around the world”. Established in 2004, it has become somewhat of an institution in the hosting world that’s been recommended by WordPress itself. SiteGround’s hosting range is similar to A2’s, and starts from the entry-level shared packages all the way to cloud products and dedicated servers. The company also offers bespoke enterprise solutions. SiteGround offers packages similar to A2’s plans — although its GrowBig and GoGeek plans cost a bit more than a comparable A2 plans. However, SiteGround does offer free daily backups across all the plans, free migration on GrowBig and GoGeek — as well as staging installation, which is handy for more professional setups. Use of resources for each plan is limited in terms of server processes, simultaneous connections, CPU seconds, RAM, cronjob intervals — and they are specific and transparent about it, which is a plus. One caveat to note is that the prices mentioned above are promotional prices for the first year of signup, and renews at a higher price after that. SiteGround's server stack consists of NGINX as a caching solution in front of Apache — which means that even SiteGround's StartUp plan is not constrained by Apache limitations. We use NGINX as a reverse proxy for caching, standing in front of an Apache server. This means that cached results get zero latency from the web server, PHP or MySQL services. The content comes our directly from the server's memory. It's as if you're fetching an HTML file — mostly networking between you and the server, and of course the size of your content. — Hristo Pandjarov They offer server locations in the UK, USA, continental Europe and Asia (Singapore). SiteGround has also recently announced support for the QUIC next-generation protocol, which will increase site loading speed even if there’s poor internet connectivity at your location. For more details check out their website. Bluehost Bluehost was founded by Matt Heaton in 2003, and enjoyed immense popularity until 2011, when it was acquired by EIG. Since the acquisition, it has remained one of the most prominent players in the hosting scene, but it has been plagued by mixed reviews regarding its user experience. Bluehost offers a similar range of products to the others — from entry-level shared plans to VPS, dedicated servers, ecommerce and WordPress packages. But it currently offers the lowest prices of the three mentioned in this category (for a 36-month term; prices go up as you'd expect for shorter terms). All but the smallest of these plans include unlimited resources (SSD Storage). However, do note that in the fine print of their Terms of Service notes: While rare, we occasionally constrain accounts utilizing more resources than should be the case in the normal operation of a personal or small business website. Hosting Recommendations Please We're looking for fast, reliable + scalable hosting for 100+ WordPress sites (of varying sizes) with WHM + cPanel. Been migrating to Bluehost Dedicated server and it's just not cutting it. Support is slow and the server has been dropping in and out over the past 24 hours + turns out the resources are capped (despit what “sales” said). “No specified limits to resources” in this case may translate to “no guaranteed resources”. Even before the EIG acquisition, Bluehost had introduced a CPU-throttling strategy — so be warned. You can read more about Bluehost's restrictions regarding resources here. On its bigger plans, Bluehost offers SSH access, cron jobs, daily backups etc. But it’s mostly oriented toward the entry-level market. Bluehost has some perks and a custom management web UI for WordPress customers. As for the server locations — Bluehost doesn’t offer straightforward information, but besides Utah, USA, they seem to have data centers in China and India (Mumbai). The post The Best Web Hosting Providers For Your Needs appeared first on SitePoint.