Introduction
Collections are an integral part of the postman. Running collections in Newman can be done in different ways. We can launch them from the postman application, or we can do it using the command line. We can do it once we have successfully set up Newman on our machine. This article will show how we can run collection from the command line using Newman.

Running Collection
After successfully setting up Newman on our machine, let us see if we can run the collections we created from the command line. So in order to do that we need a few things. So there are a few ways of running the collections in Newman. We can directly run our collections in Newman from the URL, which we generate, or export our collections in Newman along with the environment variables to run that . so let us go ahead and look at the collection options.
Sharing and Exporting Collection
Now we will see how we can share and export our collection. There is an option called export, and there is an option called a share.

So in share, we can share it with a workspace, embed it into a page, and get a public link.

We can use this public link to run our Collection from Newman. However, we should notice if we also require the environment variables or not. Without that, it will fail to run if our collection uses some environment variables.

If we are not using it, we can directly take this, and then we can use a command like "newman run" and run this collection URL. So it is simple: exporting the Collection in JSON format is best if there are environment variables.
So let us first create a folder, and we will use that to keep all our collection and environment variables for the postman API .so let us go and create a folder called "cnNewmanCollection". We want to store or export this in the "cnNewmanCollection" folder.

So the export option exports our collection in the JSON format. It will be a JSON file. So, we select that folder and keep our collection in that folder. Once we save it here, it will say our collection got exported successfully. Furthermore, we can verify that by going to that folder, which is a JSON file.

Downloading Environment
We are using an example collection file, so we do not have any environment variables. Similarly, if we needed to get environment variables, we also had to download them. Without that, it will not run. So what can we do? We would download this environment and save it in the same folder. It will again be a JSON file. In the screenshot below, we can see the option of how we download and export our environment. We require these two things to run our collection from the command line using Newman if required.

Running from Command Line
Once we have our collection and the environment, we can go back to our Newman and run this "newman run" command. And then, we need to get the collection name and give the environment if necessary. This is the kind of command we need to run in use to run our collection. So let us go ahead and do that in our command line and try Newman run.
We will go to the folder location with these particular files using the command prompt. So let us go to cd drive c drive first, and then we will go to the "cnNewmanCollection" folder. So as the subfolder, we will have all the files as JSON files. So now we will use the Newman run command, and here we will use the JSON file extension.
We should be careful naming our files beforehand, as keeping space in the middle might not let the file run correctly, as we can see below. Our file here is named "postman_collection.json". If needed, we will use the e-tag to define the environment or to pass the environment file here. Below is the complete command on how to run our collection. We can also see that it started running. It was quick and fast because it starts from the command line, and API testing does not take much time.

We can also see that this will be the kind of report it will generate in the Newman. It will tell us how many iterations we ran. Whatever the requests, which failed, how many test scripts got executed, how many failed, pre-request scripts, assertions, total duration data received, Response time Etc. So everything will be shown in this tabular format. Then it will also show us all the failures and detail their expected reasons. This is how effectively we can run our collections in Newman from the command line. We can also pass the environment if needed.