简体   繁体   中英

How can I get source code of nodejs from running app

I have accidentally delete source code of nodejs application, but this application is running, so how can I get source code back from running app?

I hope source code has been cached in some directory.

I was able to recover the full file by attaching the debugger (as TGrif suggested).

To actually recover the code:

  1. Use setBreakpoint('app.js', 10) , where 10 is a line of the code you know will be ran over again in the running process

  2. Say pause , then next until it's paused on the script you want to recover.

  3. Finally, say list(5000) , where 5000 is an arbitrarily long number of lines to list.

  4. You will now have your full script printed out, albeit with line numbers at the front, but you can use a site like this to remove them.

Hope this helps anyone who encounters this unique issue in the future, as this took me a couple hours to figure out.

There is maybe a way to retrieve some of your source code with the Nodejs debugger.

Assuming Linux OS, you need to get the process id of your application:

 $ ps -e | grep node

Next you entering your app in debug mode with something like that:

$ kill -s USR1 PID

where PID is the pid of your node app.

Then your start the debug console:

$ node debug -p PID

If you have an app console, you'll see:

Starting debugger agent.
Debugger listening on port 5858

In your debug console you should see a debug prompt and you can get available commands with:

debug> help

I am able to show some of the running app source with the list command:

debug> list(NUMBER_OF_LINE)

where NUMBER_OF_LINE is the number of source code line you want to display.

I'm not sure this is a one shot try for you or not because my source code was not deleted.
Hope you can get some results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM