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
- start.js requires core.js in code
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
Post a Comment