# Process output from 'npm outdated' command

**URL:** <https://discourse.nodered.org/t/process-output-from-npm-outdated-command/37798>\
**Category:** Share Your Projects\
**Created:** [20 December 2020 14:33 UTC](https://discourse.nodered.org/t/process-output-from-npm-outdated-command/37798 "2020-12-20T14:33:53Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [21 August 2024 15:45 UTC](https://discourse.nodered.org/t/process-output-from-npm-outdated-command/37798/5 "2024-08-21T15:45:28Z")

</div>

Hi Derek,

The flow is slightly dated now and there is another way to make node.js modules available to function nodes without having to share the `require` function in settings.js.

```auto
// End-of-line characters are different on each Operating System
// This uses Node.js features to get the right one but you
// can simply replace all of this with the appropriate string of control chars.
const require = global.get('require') // You have to add this to globals in settings.js
const EOL = require('os').EOL // OR just add `os.EOL` to settings.js instead and get that

```

Rather than the above from the original, make sure that you allow external modules in function nodes by changing the `functionExternalModules` property in settings.js to `true` and restarting nod-red.

Then you can simple reference the node.js built-in library `os` like this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/7/37dc97d9544102080db7792fcec93dd9cf43a9b4.png)

and change the function code to:

```auto
/**
 * Process the output from an `npm outdated` command.
 * Use msg.topic to allow different project folders to be tracked.
 * e.g. Global (`npm outdated -g`), 'user' for the Node-RED userDir, etc.
 */
 
// End-of-line characters are different on each Operating System
// This uses Node.js features to get the right one but you
// can simply replace all of this with the appropriate string of control chars.
const EOL = os.EOL

// Keep everything together - change this to flow or global if you want
const outdated = global.get('npm_outdated') || {}

// reset on each run - use the date entry if you want to track that
outdated[msg.topic] = {} // {updated: new Date()}

let out = outdated[msg.topic]
let heads = []

// Split the lines and process each one
msg.payload.split(EOL).forEach( (line,idx) => {
    // Don't do anything for empty lines
    if (line.length>0) {
        // Split the line by spaces, get rid of any entries that were just a space
        let tmp = line.split(' ').filter(e => e.length>0)
        
        if ( idx === 0 ) {
            // Track the headings that are on line 1
            heads = tmp
        } else {
            // Create an object for each package that needs updating
            out[tmp[0]] = {}
            tmp.forEach( (d,i) => {
                // and record the details
                out[tmp[0]][heads[i]] = d
            })
        }
    }
})

// Save - don't forget to change to global/flow if you change the get
global.set('npm_outdated', outdated)

return [
    // Output just this entry
    {
        topic: `npm/outdated/${msg.topic}`,
        parts: msg.parts,
        payload: out,
    },
    // Output everything
    {
        topic: `npm/outdated`,
        parts: msg.parts,
        payload: outdated,
    },
]

```

You should further note though that there are even easier ways to do all this. For example, simply use an exec node but make sure you include either `--json` or `--parseable` as an extra parameter, e.g. `npm outdated -g --json` and feed the output through a json node (--parseable creates a `:` separated list instead).

---

_[View the full topic](https://discourse.nodered.org/t/process-output-from-npm-outdated-command/37798)._
