In previous post have already discussed  about how to install node.js in your server. Now, Let start install specific module in node.js as based on your requirements,

This post describe to install module "exec-sync", execute shell command synchronously

Find the location of node.js

# whereis node

node: /usr/bin/node /usr/share/node /usr/share/man/man1/node.1.gz


Module : exec-sync 

If you could not found "npm" execute below command,

#  curl http://npmjs.org/install.sh | sh

Find the path and go to that execute file,

# npm install exec-sync -g


If you have installed manually, For example the node.js installed in /usr/local

# /usr/local/node-v0.10.34/bin/npm install exc-sync -g


execSync@1.0.2 install /usr/local/node-v0.10.34-linux-x64/lib/node_modules/exec-sync
node install.js

[execsync v1.0.2] Attempting to compile native extensions.
[execSync v1.0.2] Native extension compilation successful!
execSync@1.0.2 /usr/local/node-v0.10.34-linux-x64/lib/node_modules/exec-sync
└── temp@0.5.1 (rimraf@2.1.4)


Sample code structure,

var execSync = require('exec-sync'); 
var usr = execSync('echo $USER');
console.log(usr);


Error:

If you may get an Error: Cannot find module 'exec-sync'

module.js:340
    throw err;
          ^
Error: Cannot find module 'exec-sync'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Server.<anonymous> (/var/www/html/test.js:7:12)
    at Server.emit (events.js:98:17)
    at HTTPParser.parser.onIncoming (http.js:2108:12)
    at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:121:23)
    at Socket.socket.ondata (http.js:1966:22)
    at TCP.onread (net.js:527:27)


Solution:

The exec-sync module could not found the path so you can try with give full module path,

var execSync = require(' /usr/local/node-v0.10.34-linux-x64/lib/node_modules/exec-sync/'); 
var usr = execSync('echo $USER');
console.log(usr);