Coder Social home page Coder Social logo

require.main unexpected behaviour about pm2 HOT 6 CLOSED

unitech avatar unitech commented on June 17, 2024
require.main unexpected behaviour

from pm2.

Comments (6)

Unitech avatar Unitech commented on June 17, 2024

Yes it's normal.

As pm2 wrap code in a "ProcessContainer", the require use the informations of the ProcessContainer.js.

In the process container I've now set require.main.filename to the script you have launched.

It will be available soon

from pm2.

storkme avatar storkme commented on June 17, 2024

Much obliged, I look forward to trying it out :]

from pm2.

Unitech avatar Unitech commented on June 17, 2024

Pushed on Github, can you try and tell me if everything is okay ? :

$ npm install git://github.com/Unitech/pm2.git -g

from pm2.

storkme avatar storkme commented on June 17, 2024

Hi, I apologise for replying to this so late.

alex@literally:~/docs/code/node$ npm -g ll pm2

│ /usr/lib
│
└── [email protected]  (git://github.com/Unitech/pm2.git#9b18ca103eb86048fe7f04f8b4143b9059145045)
    The modern CLI process manager for Node apps with native clusterization
    git://github.com/Unitech/pm2.git
    https://github.com/Unitech/pm2
    git://github.com/Unitech/pm2.git

My test file:

console.log(require.main.filename);

using pm2 start test.js I get the following when viewed with pm2 logs:

[test out (l2)] /usr/lib/node_modules/pm2/lib/ProcessContainer.js

If you need any more information let me know -- I'll try and respond more speedily in future.

Cheers.

from pm2.

Unitech avatar Unitech commented on June 17, 2024

Np,

to resolve the script path with require.main.filename, you have to set the option MODIFY_REQUIRE to true https://github.com/Unitech/pm2/blob/master/constants.js#L19

from pm2.

subeeshcbabu-zz avatar subeeshcbabu-zz commented on June 17, 2024

Hi,

How do I set the option MODIFY_REQUIRE=true, setting this as a process env (process.env.MODIFY_REQUIRE=true) did not work as expected.

from pm2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.