A C C R E T E

Building Your First API Endpoint with Node.js and Express.js

APIs (Application Programming Interfaces) are the backbone of modern web applications, allowing communication between different services and applications. If you’re new to API development, building a simple endpoint using Node.js and Express.js is an excellent way to get started. In this guide, you’ll learn how to set up a basic API endpoint that returns JSON data, making it easy for you to grasp the fundamentals of API development. 

 

What is an Endpoint in a REST API? 

An endpoint is a specific URL where an API receives requests and sends responses. Each endpoint is associated with a particular HTTP method (such as GET, POST, PUT, DELETE) and is used to interact with the API. 

For example, if you are building a food ordering app, an API endpoint like: 

GET /restaurants
 

could return a list of available restaurants. 

In this tutorial, we’ll build a GET endpoint that returns sample data. 

 Also read: How to Set Up a Simple Node.js Server in 5 Minutes

Setting Up an Express.js Route for a GET Request 

Step 1: Install Node.js and Express 

First, ensure you have Node.js installed on your machine. If not, download it from nodejs.org. 

Then, create a project directory and initialize a Node.js project: 

mkdir my-api 
cd my-api 
npm init -y 
 

Next, install Express.js: 

npm install express 
 

Step 2: Create a Basic Express Server 

Create an index.js file and add the following code: 

const express = require('express'); 
const app = express(); 
const PORT = 3000; 
 
app.get('/', (req, res) => { 
    res.send('Welcome to my first API!'); 
}); 
 
app.listen(PORT, () => { 
    console.log(`Server is running on http://localhost:${PORT}`); 
}); 
 

Now, run the server: 

node index.js
 

Visit http://localhost:3000 in your browser, and you should see Welcome to my first API! displayed. 

 

Returning Data as a JSON Response 

Instead of sending plain text, let’s return JSON data. Modify the index.js file to create a new GET endpoint: 

app.get('/api/data', (req, res) => { 
    const sampleData = { 
        name: "John Doe", 
        age: 30, 
        occupation: "Software Developer" 
    }; 
    res.json(sampleData); 
}); 
 

Restart your server and visit http://localhost:3000/api/data. You should see: 

{ 
    "name": "John Doe", 
    "age": 30, 
    "occupation": "Software Developer" 
} 
 

 

Testing the Endpoint with Postman or a Browser 

Testing with a Browser 

For simple GET requests, you can directly visit http://localhost:3000/api/data in your browser, and the JSON response will be displayed. 

Testing with Postman 

For more advanced testing, download Postman and follow these steps: 

  • Open Postman and create a new GET request. 
  • Enter http://localhost:3000/api/data in the request URL. 
  • Click “Send.” 
  • You should see the JSON response displayed in Postman. 

 Read: How to create a REST API with Node.js and Express

Conclusion 

Congratulations! 🎉 You’ve successfully built your first API endpoint using Node.js and Express.js. You now understand: 

  • What an API endpoint is. 
  • How to create a basic Express server. 
  • How to return JSON data in a response. 
  • How to test your API using Postman or a browser. 

From here, you can expand your API by adding more endpoints, handling different HTTP methods, and connecting to a database. Happy coding!

How to Set Up a Simple Node.js Server in 5 Minutes

Are you new to Node.js and want to get started quickly? To set up Node.js server is much simpler than you might think. This guide will walk you through the process step-by-step, so you can have your first server up and running in just five minutes.

Why Node.js?

Node.js is a powerful, event-driven JavaScript runtime built on Chrome’s V8 engine. It allows you to run JavaScript on the server side, making it a popular choice for building fast, scalable network applications.

Read in depth about What is a REST API?

What You’ll Learn

  • How to install Node.js
  • Setting up a simple server
  • Creating a server.js file
  • Running your server locally
  • Handling basic GET requests

Let’s dive in!
Server concept illustration

Step 1: Installing Node.js

Before setting up your server, you need to install Node.js on your machine. Follow these steps:

  1. Download Node.js: Visit the Node.js official website and download the LTS (Long-Term Support) version for your operating system.
  2. Install Node.js: Run the downloaded installer and follow the instructions. Make sure to install the necessary tools like npm (Node Package Manager) that come bundled with Node.js.
  3. Verify Installation: After installation, open your terminal (Command Prompt on Windows, Terminal on macOS/Linux) and type the following commands to check if Node.js and npm are installed correctly:
    node -v
    npm -v

    These commands should return the version numbers of Node.js and npm respectively.

Step 2: Setting Up a Simple Server

Now that you have Node.js installed, let’s set up a simple server.

  1. Create a New Directory: Open your terminal and create a new directory for your project.
    mkdir my-first-node-server
    cd my-first-node-server
  2. Initialize a Node.js Project: Run the following command to create a package.json file, which will keep track of your project’s dependencies and scripts.
    npm init -y

Step 3: Creating the server.js File

  1. Create the server.js File: Inside your project directory, create a new file named server.js.
    touch server.js
  2. Write Basic Server Code: Open server.js in your text editor and add the following code:
    const http = require('http');
    
    const hostname = '127.0.0.1';
    const port = 3000;
    
    const server = http.createServer((req, res) => {
        res.statusCode = 200;
        res.setHeader('Content-Type', 'text/plain');
        res.end('Hello, World!\n');
    });
    
    server.listen(port, hostname, () => {
        console.log(`Server running at http://${hostname}:${port}/`);
    });

Step 4: Running the Server Locally

  1. Run Your Server: Go back to your terminal, ensure you’re in the project directory, and run the server with the following command:
    node server.js
  2. Access Your Server: Open your web browser and go to http://127.0.0.1:3000/. You should see “Hello, World!” displayed on the page.

Step 5: Handling Basic GET Requests

To make your server more interactive, let’s handle GET requests and respond with different messages based on the URL.

  1. Modify server.js to Handle GET Requests:
    const http = require('http');
    
    const hostname = '127.0.0.1';
    const port = 3000;
    
    const server = http.createServer((req, res) => {
        res.statusCode = 200;
        res.setHeader('Content-Type', 'text/plain');
    
        if (req.url === '/') {
            res.end('Welcome to the homepage!\n');
        } else if (req.url === '/about') {
            res.end('Learn more about us on this page.\n');
        } else {
            res.statusCode = 404;
            res.end('Page not found.\n');
        }
    });
    
    server.listen(port, hostname, () => {
        console.log(`Server running at http://${hostname}:${port}/`);
    });
  2. Restart the Server: Stop the current server by pressing Ctrl+C in the terminal. Then, run it again with node server.js.
  3. Test Different Routes: Visit http://127.0.0.1:3000/, http://127.0.0.1:3000/about, and a non-existent route like http://127.0.0.1:3000/contact to see how your server handles different URLs.

Conclusion

Congratulations! You’ve just set up a basic Node.js server and handled simple GET requests. This foundation will help you build more complex web applications in the future. Keep experimenting with Node.js, and you’ll discover its full potential in creating powerful server-side applications.

Happy coding!

Introduction to REST APIs: What Are They and Why Do They Matter?

In today’s fast-paced digital world, the development of web applications and services relies heavily on the exchange of data between different systems. At the heart of this interaction are APIs, and one of the most commonly used types is the REST API. But what exactly is a REST API, and why should you care about it? In this post, we’ll break down the basics and explain why understanding REST APIs is essential for anyone involved in modern web development.


What is a REST API?

REST stands for Representational State Transfer, and an API is an Application Programming Interface. In simple terms, a REST API is a set of rules that allows one software application to communicate with another over the internet using standard HTTP methods (like GET, POST, PUT, DELETE).

RESTful APIs make it easier to send and receive data between clients (like web browsers or mobile apps) and servers. They are lightweight, flexible, and stateless, meaning they don’t keep track of previous requests, making them ideal for scalable, distributed systems.


Why REST API is Important in Modern Web Development?

REST APIs are crucial because they provide a standardized way for different systems to communicate and interact, even if they are built using different programming languages or run on different platforms. They enable:

  1. Seamless Integration: REST APIs allow developers to integrate external services (like payment gateways or social media platforms) into their applications without reinventing the wheel.
  2. Scalability: By adhering to a simple architecture, REST APIs make it easier to scale applications, add features, and maintain consistent communication between multiple devices and services.
  3. Faster Development: With REST APIs, developers can leverage third-party services to save time, focusing on the core functionality of their application rather than building everything from scratch.

Examples of Common Services That Use REST APIs

Many of the services we use daily rely on REST APIs to function. Here are a few examples:

  • Social Media Platforms: Facebook, Twitter, and Instagram use REST APIs to allow third-party apps to retrieve user data, post updates, or interact with the platform’s features.
  • E-commerce Websites: Online stores like Amazon or eBay utilize REST APIs to fetch product information, process payments, or provide real-time inventory updates.
  • Google Services: Google Maps, Gmail, and Google Drive use REST APIs to share data with third-party apps, enabling users to embed maps, access emails, or manage files.

A Simple Analogy for Understanding APIs: The Waiter in a Restaurant

Imagine you’re at a restaurant. The menu lists a variety of dishes, and you decide what you’d like to eat. However, you don’t go into the kitchen to cook your meal—you rely on the waiter to communicate your order to the kitchen and bring your food back to you.

In this analogy:

  • You are the client (or consumer): You want the food (data).
  • The waiter is the API: It takes your order (request) and delivers it to the kitchen (server), then brings back the food (response).
  • The kitchen is the server: It prepares the food based on your order, just like a server processes requests from clients.

This process ensures smooth communication between the customer and the restaurant, just as a REST API facilitates communication between a client and a server.


Conclusion

Understanding REST APIs is crucial for anyone looking to develop or maintain modern web applications. They allow different systems to interact seamlessly, enabling the creation of complex, scalable, and feature-rich applications. Whether you’re a beginner just starting out or a seasoned developer looking to brush up on the basics, mastering REST APIs is an essential skill in today’s tech-driven world.

How to Find IT Internship in Gandhinagar Infocity: A career Guide!

Solve you internship confusion for last semester. Find internship in gandhinagar, gujarat.

The Stress of the Final-Year Internship Hunt 

It’s your last semester, and instead of excitement, a wave of anxiety hits. You’re bombarded with endless questions: 

Where should I find an internship? 

Which company is best for me? 

What technology should I choose for my internship? 

Every student around you seems to be racing in different directions, adding to the confusion. You overhear conversations like “Abhi market mein ye chal raha hai” (This is trending in the market right now) or “This technology is a goldmine for making money.” But deep inside, you’re unsure—how do you find the right IT Internship in Gandhinagar Infocity or any other city during this crucial phase? 

What to Consider When Choosing a Company for Your Internship 

Choosing a company is one of the most important steps in shaping your career. For example, you’re looking for an IT internship in Gandhinagar Infocity, especially at a well-established IT company in Infocity Gandhinagar, here’s what you should keep in mind: 

  • Company Size: Do you prefer a startup environment or a large corporation? Startups often offer more hands-on experience, while larger companies provide structured learning opportunities. 
  • Years in Business: Companies like Accrete Infosolution Technologies—a trusted IT company in Gandhinagar Infocity—offer stability and well-structured training programs. 
  • Technologies Used: Make sure the company works with up-to-date technologies which focus on cutting-edge technology, ensuring you gain relevant skills. 
  • Location: Is the company’s location convenient? Long commutes can affect your productivity. If you’re based in Gandhinagar, IT companies in Infocity Gandhinagar, Gift City Gandhinagar can be a prime choice.

Paid, Unpaid, or Stipend-Based Internships 

Internships vary widely: 

  • Paid: You may need to pay for specialized training programs. 
  • Unpaid: Experience is the primary gain, though some might offer a small stipend. 
  • Stipend-Based: These provide some financial support, helping make the internship more sustainable. 

The Technology Dilemma: How to Choose? 

Choosing the right technology is often the hardest part. Many students get caught in the “rat race” and follow trends without much thought. When finding an internship, focus on your core skills over trendy buzzwords.

Skill assesment is important for findinng right internship!

 

Skill Assessment Before Choosing Technology 

Evaluate your strengths and weaknesses before diving into a technology. A skill assessment test from trusted resources like EPAM Campus can help you identify where you stand and what technologies would suit you best. 

Tips for Finding the Right Internship 

Now that you’ve figured out the essentials, here are practical steps for finding the right internship: 

  • Start Early: Start your search at least two months before your semester begins. Make a list of potential companies around Gandhinagar or any nearest suitable city. 
  • Visit Companies: If possible, visit IT companies in that city to understand their work culture and internship structure. 
  • Rank Companies: After gathering information, rank your choices based on company size, internship structure, technologies used, convenient location and job placement potential. 

Popular Technologies to Consider 

Here’s a list of popular technologies you might want to explore in your internship: 

Development 

.NET Core, NodeJS, ReactJS, AngularJS, Python, Flutter, PHP 

Cloud Management 

Amazon Web Services (AWS), Microsoft Azure, Google Cloud 

Testing 

Automated Testing Tools (Selenium, QTEngine) 

Designing

UI/UX designing, Graphic designing, WordPress website designing

Marketing 

Digital marketing, Sales, Content writing

Rahul’s Internship Story: Figuring It Out Along the Way 

The Confusion 

Rahul, a final-year IT student from Gandhinagar, felt lost. Everyone around him talked about AI and full-stack development, but none of it really clicked. He didn’t know where to start or what was best for him. 

Taking a Chill Approach 

Rahul decided to assess his strengths. After taking a skill assessment, he found he was drawn to cloud computing. This clarity helped him search for an IT internship in Gandhinagar Infocity, where he found a company that worked with technologies he was interested in. 

Discovering a Passion 

Rahul’s internship experience with a local IT company in Gandhinagar Infocity helped him uncover a genuine interest in cloud management—a field he hadn’t considered before. 

Conclusion: Overcoming the Internship Dilemma 

Finding the right internship is a big step. Focus on what truly matters—your skills, company culture, and long-term goals—to make an informed choice. 

Whether you’re interested in a large corporate companies or a smaller IT company following your passion and building relevant skills is the key. 

 

Start Your Internship Journey with Accrete Infosolution Technologies! 

Accrete Infosolution Technologies, a leading IT company in Gandhinagar Infocity, provides guided IT internship in Gandhinagar Infocity and hands-on training. If you’re a final-year student looking to enhance your skills with an internship in Gandhinagar, explore opportunities with us. We’re here to help you build a solid foundation for your career.

Contact us at: hr@accreteinfo.com
Fill out the form to show interest in Internship Program- https://forms.office.com/r/cA8nGKJ2wT

Find an agent now

Telephone

+91 079 232 13063

Time Schedule

Office Time

Mon - Fri: 9:00 - 18:00