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. 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 poorer performance.
Here is a short list of currently popular languages and frameworks for server-side scripting.
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.
Below is a Hello World program written using Laravel. The code specifies that a GET request to the /greeting URL path should execute an anonymous function which returns the “Hello, World!” string.
use Illuminate\Support\Facades\Route; Route::get('/greeting', function () { return 'Hello, World!'; });
Laravel offers extensive documentation, a solid support community, and a number of tools and packages. Learning Laravel after working with plain PHP can lead to cleaner code and a deeper understanding of the abstracted process it replaces.
Node.js (JavaScript)
You have learned a lot about JavaScript for client-side scripting, but Node.js gives you the option of running JavaScript on the server-side as well. 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 to entry can be lower for full-stack development.
Below is a Hello World program written using Node.js. Notice that the code requires you to handle many of the low level details that are handled automatically in Apache and PHP. you have to create a server object, tell it what port to listen on, and write the response code and headers yourself. Furthermore, this simple program responds to any HTTP Request with “Hello, World!”, no matter what path the user specifies.
const http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World!'); }).listen(8080);
Node.js is lightweight and resource-efficient, but lacks much of the built-in support you may expect after working with Apache and PHP. Typically, Node.js servers are run using additional frameworks. If you are determined to use Node.js on its own, W3Schools has a few tutorials that can help you get started.
Express (JavaScript)
Express is a framework that adds a minimal but powerful set of tools to the Node.js core. 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.
Below is a Hello World program written using Express. Like the Laravel snippet above, the code specifies that a GET request to the /greeting URL path should execute an anonymous function which returns the “Hello, World!” string. Note that with Express you still have to manually define an app object and start the server yourself.
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'));
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.
Writing a Hello World program in Rails is a complicated affair involving the definition of a route, a controller, an action, and a view.
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.
Like Ruby on Rails, Hello World in django requires a number of setup steps. W3Schools has tutorials that can help you get started.
Feedback/Errata