পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Friday, February 17, 2017

ExpressJS - Hello World

So we have set up the development, now it is time to start developing our first app using express. Create a new file called index.js and type the following in it.
var express = require('express');
var app = express();

app.get('/', function(req, res){
    res.send("Hello world!");
});

app.listen(3000);
Save the file, go to your terminal and type
nodemon index.js
This will start the server. To test this app, open your browser and go to http://localhost:3000 and you should get the message,
Hello world

How this app works?

The first line imports express in our file, we have access to it through the variable express. We use it to create an application and assign it to var app.
app.get(route, callback) - This function tells what to do when a get request at the given route is called. The callback function has 2 parameters, request(req) and response(res). The request object(req) represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, etc. Similarly, the response object represents the HTTP response that the express app sends when it receives a HTTP request.
res.send() - This function takes an object as input and it sends this to the requesting client. Here we are sending the string "Hello World!".
app.listen(port, [host], [backlog], [callback]]) - This function binds and listens for connections on the specified host and port. Port is the only required parameter here.
Argument Description
port a port number on which the server should accept incoming requests
host Name of the domain. You need to set it when you deploy your apps to the cloud.
backlog The maximum number of queued pending connections. The default is 511.
callback An asynchronous function that is called when the server starts listening for requests.

No comments:

Post a Comment