javascript - Node.js cluster child process path -


started exploring node.js , faced following problem

let's i've got 3 files: start.js, core/core.js , core/child.js

  1. start.js requires core.js in code
  2. core.js creates child process (core/child.js) using cluster these settings

    cluster.setupmaster({     exec: './core/child.js' }); 

core.js , child.js in same folder, error (not found) if use

exec: './child.js' 

didn't find similar in documentation, however

require('./child.js') 

works perfectly. have no problem if path bit longer, trying understand why can't use path local core.js

require() works relative location of current code file, other operations in node.js (including launching other processes) relative current working directory process.cwd().

if need generate path relative current file, can use __dirname variable available in every module @ runtime.

var childpath = require('path').join(__dirname, 'child.js'); 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -