UNIVERSITY INSTITUTE OF COMPUTING
MASTER OF COMPUTER APPLICATIONS
Backend Technologies
23CAH-705
UNIT-1 DISCOVER . LEARN . EMPOWER
1
Backend Technologies • Introduction:
Course Outcome
CO Title Level
Number Introduction to full stack
CO1 Understand the architecture and Remember development:
design principles of back-end
systems, including APIs, web Introduction to full stack
services, and serverless computing development, Introduction to NodeJS,
CO2 Apply the knowledge and skills features, environment setup, REPL,
acquired to develop and deploy NPM. Node modules, Call backs,
back-end applications, using tools Understand
event loop, stream and file system,
such as [Link]
Global Objects, Utility Modules,
Understand the working of Git to HTTP module.
CO3 upload the created project Understand
2
Outline
Introduction to full stack development
Introduction to full stack development,
Introduction to NodeJS, features,
environment setup,
REPL, NPM.,
Node modules,
Call backs, event loop,
stream and file system,
Global Objects,
Utility Modules,
HTTP module.
3
Nodejs Features:
•Asynchronous and Event-Driven:
•All APIs of [Link] are asynchronous, meaning they are non-blocking. This allows [Link] to
handle multiple requests concurrently without waiting for any function to return.
•Single-Threaded but Highly Scalable:
•[Link] uses a single-threaded model with event looping, which helps it handle many
connections simultaneously. The event mechanism enables the server to respond in a non-blocking
way, making it highly scalable.
•High Performance:
•[Link] is built on the V8 JavaScript engine, which compiles JavaScript directly to native
machine code. This, combined with its asynchronous nature, provides high performance for I/O-
bound applications.
•No Buffering:
•[Link] applications output data in chunks without buffering. This is particularly beneficial for
applications that need to process large amounts of data in real-time.
•Cross-Platform Compatibility:
•[Link] runs on various platforms (Windows, Linux, Unix, MacOS, etc.), making it versatile for
different development environments.
•NPM (Node Package Manager):
•NPM provides a large repository of over a million packages. It makes it easy to manage project
dependencies and share code with other developers.
4
• Environment Setup
• To start using [Link], you need to set up the environment on your local
machine.
• Step 1: Download [Link]
• Visit the official [Link] website: [Link]
• Download the installer for your operating system (Windows, macOS, or
Linux).
• Step 2: Install [Link]
• Windows:
• Run the downloaded installer and follow the installation steps.
• Ensure the "Add to PATH" option is selected during the installation.
• macOS:
• Open the .pkg file you downloaded and follow the prompts to install [Link]. 5
Contd…
Linux:
• You can use a package manager to install [Link]. For example, on Ubuntu, you
can run:bash
• sudo apt update sudo apt install nodejs sudo apt install npm
• Alternatively, you can use a version manager like nvm (Node Version Manager)
to install [Link]:bash
• curl -o- [Link] |
bash source ~/.bashrc nvm install node
6
Step 3: Verify Installation
• To verify that [Link] and npm (Node Package Manager) are installed correctly,
open your terminal or command prompt and run:
• bash
• node -v npm -v
• You should see the version numbers of [Link] and npm.
• Writing Your First [Link] Application
• Create a new directory for your project:
• bash
• mkdir mynodeapp cd mynodeapp
7
Writing Your First [Link] Application
• Create a new directory for your project:
• bash
• mkdir mynodeapp cd mynodeapp
• Create a file named [Link]:
• javascript
• // [Link] const http = require('http'); const hostname = '[Link]'; const
port = 3000; const server = [Link]((req, res) => { [Link] =
200; [Link]('Content-Type', 'text/plain'); [Link]('Hello World\n'); });
[Link](port, hostname, () => { [Link](`Server running at [Link]
{hostname}:${port}/`); });
8
Run your [Link] application:
• bash
node [Link]
Open your web browser and navigate to [Link] You
should see "Hello World" displayed.
Additional Tools and Packages
[Link]:
• Express is a fast, unopinionated, minimalist web framework for [Link], often
used to build web applications and APIs.
• Install Express:bash
• npm install express
9
• Nodemon:
• Nodemon is a utility that automatically restarts your [Link] application
when file changes are detected.
• Install Nodemon:bash
• npm install -g nodemon
• Use Nodemon to run your app:
bash
nodemon [Link]
10
REPL
A Read-Eval-Print Loop (REPL) is an interactive programming environment that takes
user inputs (reads), evaluates them (eval), and then returns the result to the user
(prints). This loop continues until the user exits the environment. REPLs are commonly
used in many programming languages, providing a convenient and quick way to test
code snippets, debug, and explore language features. Here’s a bit more detail:
Read: The REPL takes input from the user, which is usually a single expression or
statement.
• Eval: The input is then evaluated or executed by the language interpreter or compiler.
• Print: The result of the evaluation is printed out for the user to see.
• Loop: The process repeats, allowing the user to input more code
11
12
Environment Setup
To get started with [Link], follow these steps:
1. Download and Install [Link]
• Download:
• Visit the official [Link] website.
• Download the installer for your operating system (Windows, macOS, or Linux).
• Install:
• Run the installer and follow the on-screen instructions.
• The installer will also install NPM (Node Package Manager) along with [Link].
2. Verify Installation
After installing [Link], you can verify the installation using the
command line.
13
Open Terminal or Command Prompt.
Check [Link] version:
• node -v
• This should output the installed version of [Link].
Check NPM version:shCopy code
• npm -v
• This should output the installed version of NPM.
3. Create a Simple [Link] Application
• Create a Project Directory:
• Open your terminal or command prompt.
• Create a new directory for your project:shCopy code
• mkdir my-node-app cd my-node-app
• Initialize the Project:
• Initialize a new [Link] project using NPM:shCopy code
• npm init -y
• This command will create a [Link] file with default settings.
• Create a Simple Server:
• Create a new file named [Link] in your project directory.
• Add the following code to [Link]
14
// Load the http module to create an HTTP server.
const http = require('http');
// Configure the HTTP server to respond with "Hello, World!" to all requests.
const server = [Link]((req, res) => {
[Link](200, { 'Content-Type': 'text/plain' });
[Link]('Hello, World!\n');
});
// Listen on port 3000 and IP address [Link]
[Link](3000, '[Link]', () => {
[Link]('[Link] server is running at [Link]
});
15
Run the Application:
In your terminal or command prompt, navigate to your project directory and
run the server:
• node [Link]
You should see the message:
• [Link] server is running at [Link]
Test the Server:
• Open a web browser and navigate to [Link]
• You should see the message: Hello, World!.
16
[Link] REPL (Read-Eval-Print Loop)
The [Link] REPL (Read-Eval-Print Loop) is an interactive shell that processes [Link]
expressions. It reads the code you input, evaluates it, prints the result, and then loops
to read more code. This environment is very useful for experimenting with JavaScript
and [Link] code, debugging, and performing quick calculations.
Key Features of [Link] REPL:
• Interactive Execution:
• Allows you to execute JavaScript code in real-time and see the results immediately.
• Evaluation:
• Evaluates expressions and outputs the results.
• Multiline Expressions:
• Supports multiline expressions, making it easier to test larger blocks of code.
• Command History:
• Maintains a history of executed commands, which you can navigate using the up and down
arrow keys.
17
• Variable and Function Definitions:
• You can define and use variables and functions within the REPL session.
• Editor Mode:
• Allows you to enter an editor mode to write and edit multiline code more comfortably.
• REPL Commands:
• Special REPL commands starting with a dot (.) to perform specific actions like loading files or
saving sessions.
Using the [Link] REPL:
• Starting the REPL:
Open your terminal or command prompt.
Type node and press Enter:
$ node
You will see the > prompt indicating that the REPL is ready to accept commands.
18
• Executing Code:
• Type JavaScript expressions and press Enter to see the results. For example:shCopy code
• > 2 + 3 5 > const name = '[Link]'; undefined > name '[Link]'
• Multiline Expressions:
• Use Shift + Enter to write multiline code:shCopy code
• > function add(a, b) { ... return a + b; ... } undefined > add(5, 10) 15
• Command History:
• Use the up and down arrow keys to navigate through the history of commands you have entered.
• REPL Commands:
• Special commands that start with a dot:
• .help - Displays help for special commands.
• .editor - Enters editor mode for writing multiline code.
• .exit - Exits the REPL.
• .save [filename] - Saves the current REPL session to a file.
• .load [filename] - Loads a file into the current REPL session.
• Using the Editor Mode:
• Type .editor and press Enter:shCopy code
• > .editor
• You will enter a new mode where you can write multiline code. Press Ctrl + D to execute the code and
return to the REPL prompt. 19
• Example REPL Session
• Here's a sample REPL session demonstrating various features:
$ node
>2+3
5
> const name = '[Link]';
undefined
> name
'[Link]'
> function multiply(a, b) {
... return a * b;
... }
undefined
> multiply(4, 5)
20
> .help
20
> .help
.break Sometimes you get stuck, this gets you out
.clear Alias for .break
.editor Enter editor mode
.exit Exit the REPL
.help Print this help message
.load Load JS from a file into the REPL session
.save Save all evaluated commands in this REPL session to a file
> .editor
// Entering editor mode (Ctrl+D to finish, Ctrl+C to cancel)
const greet = (name) => {
return `Hello, ${name}!`;
}
[Link](greet('[Link]'));
(null editor)
> Hello, [Link]!
undefined
> .exit 21
NPM (Node Package Manager)
NPM, or Node Package Manager, is a crucial tool for [Link] development. It is the default package
manager for [Link], and it comes bundled with the [Link] installation. NPM allows developers to
install, share, and manage reusable code packages, making it easier to develop and maintain [Link]
applications.
Key Features of NPM:
• Package Installation:
• NPM enables you to install packages (modules) from the NPM registry, a vast repository of open-source code.
• Dependency Management:
• NPM manages dependencies for your project, ensuring that the correct versions of packages are installed.
• Versioning:
• It handles versioning of packages, allowing you to specify which versions of a package your project depends on.
• Scripts:
• NPM allows you to define scripts in the [Link] file, which can be used to automate common tasks like
testing, building, and deploying your application.
22
Installing NPM
NPM is installed automatically with [Link]. To check if NPM is installed, and to verify the installed
version, you can use the following commands:
npm -v
Using NPM
• Here are some common NPM commands and how to use them:
• Initialize a Project:
• Create a [Link] file in your project directory using the following command:
npm init
• Follow the prompts to set up your project, or use the -y flag to automatically set up with default values:
npm init -y
23
To install a package globally (available across all projects), use the -g flag:
npm install -g <package-name>
• Uninstalling Packages:
• To uninstall a package and remove it from your [Link] file, use:
npm uninstall <package-name>
• Updating Packages:
• To update all the packages to their latest versions, use:
npm update
24
Running Scripts:
• You can define custom scripts in the scripts section of your [Link]
file:
{
"scripts": {
"start": "node [Link]",
"test": "mocha"
}
}
Run these scripts using:
npm run <script-name>
Example:
npm run start
25
Example of Setting Up a Project
Here is an example of how to set up a simple project with NPM:
• Create a Project Directory:
• Open your terminal or command prompt and create a new directory for your
project:
mkdir my-node-app cd my-node-app
• Initialize the Project:
• Initialize a new [Link] project:
npm init -y
• Install Dependencies:
• Install a package, for example, Express, which is a web framework for [Link]:
npm install express
• Create [Link] File:
• Create a file named [Link] in your project directory and add the following code:
26
const express = require('express');
const app = express();
const port = 3000;
[Link]('/', (req, res) => {
[Link]('Hello, World!');
});
[Link](port, () => {
[Link](`Example app listening at [Link]
});
Run the Application:
• Add a start script to your [Link] file
27
{
"scripts": {
"start": "node [Link]"
}
}
Start your application:
npm run start
• Open a web browser and navigate to
[Link] to see the message "Hello, World!".
28
References
• [Link]
251
• [Link]
[Link]?id=uUMQEAAAQBAJ&redir_esc=y
• [Link]
• [Link]
29
THANK YOU
30