---
title: "Comment by anatawa12 on \"Cleanup the node_modules for a lighter Lambda Function\" | Hashnode"
description: "In my opinion, $ npm prune --production is better to remove devDependencies because npm install downloads dependencies but npm prune only removes devDependencie"
url: "https://hashnode.com/posts/cleanup-the-nodemodules-for-a-lighter-lambda-function/5fd066a108c38b30aa6fed5a/comment/5fd08b3efb1375358b507a0b"
---

[Discussion](https://hashnode.com/posts/cleanup-the-nodemodules-for-a-lighter-lambda-function/5fd066a108c38b30aa6fed5a)

Comment [Cleanup the node\_modules for a lighter Lambda Function](https://hashnode.com/posts/cleanup-the-nodemodules-for-a-lighter-lambda-function/5fd066a108c38b30aa6fed5a)

[anatawa12](https://hashnode.com/@anatawa12)

[Dec 9, 2020](https://hashnode.com/posts/cleanup-the-nodemodules-for-a-lighter-lambda-function/5fd066a108c38b30aa6fed5a/comment/5fd08b3efb1375358b507a0b)

In my opinion,

```
$ npm prune --production
```

is better to remove devDependencies because `npm install` downloads dependencies but `npm prune` only removes devDependencies, doesn't downloads dependencies.

Small Benchmark with your example package.json:

```
$ cat package.json
{
  "name": "layerjs",
  "version": "1.0.0",
  "description": "This is the lambda layer generated for the service",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "jsonwebtoken": "^8.5.1",
    "pdfkit": "^0.11.0",
    "uuid4": "^2.0.2",
    "xlsx": "^0.16.9"
  },
  "devDependencies": {
    "aws-sdk": "^2.805.0"
  }
}
$ npm install # reinstall all dependencies
...
$ rm -rf node_modules
$ time npm install --production
...
added 146 packages from 120 contributors and audited 158 packages in 3.491s
...
npm install --production  3.29s user 1.81s system 99% cpu 5.122 total
$ npm install # reinstall all Dependencies
...
$ time npm prune --production
...
removed 12 packages and audited 146 packages in 1.3s
...
npm prune --production  1.52s user 0.44s system 95% cpu 2.054 total
```

[Vikas Solegaonkar](https://hashnode.com/@solegaonkar)

[Dec 9, 2020](https://hashnode.com/posts/cleanup-the-nodemodules-for-a-lighter-lambda-function/5fd066a108c38b30aa6fed5a/comment/5fd08b3efb1375358b507a0b#reply-5fd0912b6e02ab3685f912a5)

Thanks for the insight. What I showed above is just a reminder to delete the node\_modules that is already collected in the previous step.

Ofcourse, in real live, we don't have to install, delete and install once again. A simple `npm install --production` is enougn. Perhaps I need to elaborate on that point.

Thanks for pointing out
