Programming on the Server Side
43 Server-side Languages and Frameworks
Learning Outcomes
When you have completed this chapter, you will be able to:
- Explain some key features and the main advantages of using various server-side languages and frameworks.
This textbook focusses on plain PHP as the server-side language. Learning the fundamentals of server-side logic in PHP is a good choice for beginners and can make it easier to transition into modern PHP frameworks and other server-side languages. Choosing a framework to use may be difficult, but taking into account factors such as familiarity with the language, project requirements, and community support may help guide your decision. Some frameworks offer a great deal of flexibility at the cost of added complexity, while others offer rapid development with many built-in features at the cost of performance.
Below is a short list of currently popular languages and frameworks used for server-side scripting based on PHP and other coding languages.
Laravel (PHP)
Laravel is a modern PHP framework released in 2011 and follows the model-view-controller (MVC) architectural pattern. It aims to simplify many common web development tasks and aid in scaling complex web applications. It is widely used in professional development and provides features right out the box such as a routing systems, database migrations and seeders, and tools for authentication and authorization.
As an example of a basic routing in Laravel we can look at the documentation. In this case, a GET request to the /greeting URL path executes the anonymous function which returns the defined string but abstracting the lower-level HTTP handling.
use Illuminate\Support\Facades\Route; Route::get('/greeting', function () { return 'Hello World'; });
Laravel also places great importance on the developer experience by providing extensive documentation and official packages such as Laravel Sail and Laravel Sanctum. Learning Laravel after working with plain PHP can allow for cleaner code and a deeper understanding of the abstracted process it replaces.
Node.js (JavaScript)
We have learnt a lot about JavaScript for client-side scripting but through Node.js we have the option of running JavaScript outside of a browser. Released in 2009 by Ryan Dahl, Node.js is an open-source runtime environment running on the V8 JavaScript engine originally developed by Google for the Chrome browser.
Node.js allows developers to use JavaScript as a single language both on the client and the server side, meaning that the barrier of entry can be lower for full-stack development. In 2010 a package manager called npm was introduced for publishing and sharing Node.js packages, designed to simplify the process of using already created code as packages.
Node.js is very lightweight and resource-efficient, making use of asynchronous execution, but lacks many built-in features for handling things like routing, middleware, or templating. It provides a minimal set of modules, making it very low level, so typically it is run with additional frameworks on top of it.
Express (JavaScript)
Express is a framework making use of Node.js, that adds a minimal but powerful set of tools for server-side scripting. It was released in 2010 and is known for its simplicity and speed. Instead of having to manually create low-level logic using Node.js modules, Express provides higher-level features such as routing systems, middleware support, and templating support. It also allows for easy integration with databases, authentication systems, and client-side frameworks such as React or Vue.
const express = require('express'); const app = express(); app.get('/greeting', (req, res) => { res.send('Hello World'); }); app.listen(3000, () => console.log('Server running on port 3000'));
Here we see the JavaScript code used in a similar manner to the Laravel snippet above. Note that in this case we manually define the app object and start the server with app.listen while Laravel would have higher-level server handling.
Express is often used as the back-end of the MERN stack, comprising of MongoDB, Express, React, and Node.js, making it a key part of modern full-stack JavaScript applications.
Ruby on Rails (Ruby)
Ruby on Rails (also called Rails) was released in 2004 and brought about innovative features such as seamless database table integration and automated code generation for quick development. It provides mostly all standard mechanisms out of the box and includes tools for templating, routing, and testing. While its popularity has declined, it is still developed and very prevalent today, and has greatly influenced other similar frameworks with its design patterns and development practices.
Django (Python)
Django is a high-level web framework for Python released in 2005 and provides almost everything a developer might need out of the box. It follows a similar design philosophy to Ruby on Rails and was designed to help developers build secure and maintainable web apps quickly. Because it has everything built-in, the components all work together and are consistent in their patterns. Django has grown in popularity based on Python’s own popularity, making for a larger developer base and more approachable code.
Feedback/Errata