Products
Products
Video Hosting
Upload and manage your videos in a centralized video library.
Image Hosting
Upload and manage all your images in a centralized library.
Galleries
Choose from 100+templates to showcase your media in style.
Video Messaging
Record, and send personalized video messages.
CincoTube
Create your own community video hub your team, students or fans.
Pages
Create dedicated webpages to share your videos and images.
Live
Create dedicated webpages to share your videos and images.
For Developers
Video API
Build a unique video experience.
DeepUploader
Collect and store user content from anywhere with our file uploader.
Solutions
Solutions
Enterprise
Supercharge your business with secure, internal communication.
Townhall
Webinars
Team Collaboration
Learning & Development
Creative Professionals
Get creative with a built in-suite of editing and marketing tools.
eCommerce
Boost sales with interactive video and easy-embedding.
Townhall
Webinars
Team Collaboration
Learning & Development
eLearning & Training
Host and share course materials in a centralized portal.
Sales & Marketing
Attract, engage and convert with interactive tools and analytics.
"Cincopa helped my Enterprise organization collaborate better through video."
Book a Demo
Resources
Resources
Blog
Learn about the latest industry trends, tips & tricks.
Help Centre
Get access to help articles FAQs, and all things Cincopa.
Partners
Check out our valued list of partners.
Product Updates
Stay up-to-date with our latest greatest features.
Ebooks, Guides & More
Customer Stories
Hear how we've helped businesses succeed.
Boost Campaign Performance Through Video
Discover how to boost your next campaign by using video.
Download Now
Pricing
Watch a Demo
Demo
Login
Start Free Trial
Express.js is a framework built on top of Node.js’s core HTTP module, which provides a structured way to define routes, handle HTTP methods, and manage request and response objects. Instead of setting up listeners and parsing requests, Express offers methods like app.get() and app.post() that support middleware for tasks like JSON parsing, logging, and authentication. Express simplifies server logic while allowing full control over request flow and response handling. Setting Up Express.js in a Node.js Project To use Express, start creating a Node.js project environment, initialize a package.json file to manage dependencies, and install Express as a runtime dependency. Run the following command. npm init -y npm install express Explanation: npm init -y creates a package.json with default values. npm install express adds Express to the project as a runtime dependency. Creating a Basic HTTP Server with Express After installing Express, create a new file (e.g., server.js ) and set up a web server that listens for HTTP requests. Example: const express = require('express'); const app = express(); const PORT = 3000; app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); }); Explanation: express() initializes the app. app.listen() binds the server to port 3000 . Defining Routes and Handling Requests Express defines endpoints using HTTP method-specific functions like app.get() or app.post() . Each route matches a specific path and handles requests by executing a callback to request and response objects, defining a basic GET route, and returning a plain-text response. Example: app.get('/', (req, res) => { res.send('Hello, Express!'); }); Explanation: app.get('/') defines a route handler for HTTP GET requests to the root path. (req, res) are the request and response objects. res.send() sends a plain-text response to the client. Returning JSON Responses Express provides the res.json() method to send structured JSON responses. It automatically sets the Content-Type header to application/json and serializes the JavaScript object into a JSON string. It is commonly used to return data in a format suitable for frontend applications or other client services to process. Example: app.get('/api/user', (req, res) => { res.json({ id: 1, name: 'Alice' }); }); Explanation: This route returns a JSON object for the /api/user endpoint. res.json() sets the appropriate Content-Type header and sends a serialized object. Handling Route Parameters Express routes include dynamic segments, allowing values to be extracted directly from the URL, defined with a colon (e.g., :id ), accessed through req.params, and explains how to define and handle route parameters for dynamic endpoints. Example: app.get('/api/user/:id', (req, res) => { const userId = req.params.id; res.send(`User ID: ${userId}`); }); Explanation: :id defines a dynamic route segment. req.params.id retrieves the value from the URL. Parsing JSON in Incoming Requests When an API receives JSON in the request body, Express requires middleware to parse that data into a usable object. The express.json() enables this by automatically parsing application/json payloads and attaching them to req.body . Example: app.use(express.json()); app.post('/api/data', (req, res) => { const body = req.body; res.json({ received: body }); }); Explanation: express.json() is middleware that parses application/json request bodies. req.body contains the parsed JSON object. Serving Static Video Files For small or unprotected video files, you can use Express’s built-in static middleware to serve .mp4, .webm , or similar formats, useful for quick testing or internal tools that don’t require streaming capabilities. Example: app.use(express.static('public')); If you have a file located at public/sample.mp4 , it can be accessed directly via: http://localhost:3000/sample.mp4 Explanation: express.static('public') serves all files inside the public/ folder at the root URL. This uses the standard
tag to embed and play a static video file, but it does not support seeking or scrubbing in large files because HTTP range requests are not handled , and the browser downloads the entire video to enable playback.
Streaming Video with HTTP Range Support For large video files, when the user needs to scrub/seek through the content, you must implement support for HTTP range requests , allowing the browser or media player to request specific chunks of the video rather than downloading the entire file at once. Example: const fs = require('fs'); const path = require('path'); app.get('/video', (req, res) => { const videoPath = path.join(__dirname, 'videos', 'sample.mp4'); const stat = fs.statSync(videoPath); const fileSize = stat.size; const range = req.headers.range; if (range) { const [start, end] = range.replace(/bytes=/, '').split('-').map(Number); const chunkEnd = end || fileSize - 1; const chunkSize = chunkEnd - start + 1; const stream = fs.createReadStream(videoPath, { start, end: chunkEnd }); res.writeHead(206, { 'Content-Range': `bytes ${start}-${chunkEnd}/${fileSize}`, 'Accept-Ranges': 'bytes', 'Content-Length': chunkSize, 'Content-Type': 'video/mp4', }); stream.pipe(res); } else { res.writeHead(200, { 'Content-Length': fileSize, 'Content-Type': 'video/mp4', }); fs.createReadStream(videoPath).pipe(res); } }); Explanation: Checks for the Range header to determine the requested byte range. Responds with status 206 Partial Content and correct Content-Range and Content-Length headers. Streams only the requested portion of the file to the client. Allows smooth seeking/scrubbing in most browsers and video players. Handling Video Uploads Express uses the multer middleware to process incoming multipart/form-data requests and saves uploaded files to a directory on the server and allowing the server to accept, store video files sent through an HTML form or API request. Installation: npm install multer Example: const multer = require('multer'); const upload = multer({ dest: 'uploads/' }); app.post('/upload', upload.single('video'), (req, res) => { res.json({ file: req.file }); }); Explanation: multer({ dest: 'uploads/' }) saves uploaded files to the uploads/ folder. upload.single('video') expects a single file with the name='video' in the form. req.file contains metadata about the uploaded file.