Steps to create Basic Express Application

Step 1: Create a basic node application with the below npm command.

npm init -y

`-y` flag is used to say yes to all of the details asked by npm, if you need to change any option, answer it manually by omitting the flag in the command.

init node app

Step 2:

  • Install the express.js and multer dependency using the npm install command.
  • The dependencies will be installed under a folder called node_modules under the current directory.
npm install --save express multer

installing dependencies

  • –save option is used to add these libraries in the package.json file as a dependency for running the application.

Step 3: Create a file named server.js under the same directory to host the express server. Add the below code to bootstrap the server for giving a hello message on hitting the “/” endpoint

Javascript




const express = require("express");
const app = express();
 
// port for our project to run
const PORT = 8080;
 
// A simple greeting message to
// test the app
app.get("/", (req, res) => {
  res.send("Hello from Express!");
});
 
// Start the server using listen method of express
// pass the port and callback function on successful start
app.listen(8080, () => {
  console.log(`server is started and
               listening at port: ${PORT}`);
});


A simple get method is added to the “/” path to check whether the app is starting fine and responding back to the request.

Step 4: Start the server and test the initial greeting message in Postman, to start the server use the below command.

npm start

Step 5:

  • Once the server is started, open Postman and create a new HTTP request using the `New` button located after My Workspace in the screen.
  • Enter your server url in the address bar of the request and select the HTTP method for the request, here => http://localhost:8080/ and GET method.
  • Click the send button to send the request to the server.

initial hello ouput

  • Once the request has been sent, the server will respond with plain text saying “Hello from Express!”.
  • You can find the response from the server in the below area of the request under the Body tab.

How to Handle file upload in Node with Multer and Postman

In this article, we will discuss about file upload functionality using Node, Multer and Postman. File Uploading is a significant functionality of any web service to get the data from the users in the form of files.

To implement this feature we will use Node JS with Express and Multer library. Finally, we will use the Postman API platform to test the REST endpoint for file uploading.

Similar Reads

Prerequisites

The following tools should be installed in your system to follow along with this article, incase you don’t have it already installed use the given links (node, postman) to download and install it in your system. Make sure you are using the same version of the tools mentioned....

Approach to handle file upload in Node

Let’s discuss our approach for implementing the file upload functionality in Node.js....

Handling File Upload in Node JS

Follow the step by step procedure to handle file upload in node, create a folder to store the project files and open that folder in VS Code or any of your preferred Text Editor. The entire workflow has been divided into three major process,...

Steps to create Basic Express Application

Step 1: Create a basic node application with the below npm command....

Adding File Upload functionality with Multer

...

Testing File Upload with Postman

Step 6: Create a file named file-upload.js in the current directory to store the file upload handling functions and Multer configuration....

Contact Us