debugging-node-server
Debugging NODE server​
source: video https://drive.google.com/open?id=1gAcceeO4dqqMAxgpv1iFwkDEki-i3miW
1 install VS code https://code.visualstudio.com/download
2 on terminal make sure to run foreman for POWr repo foreman start -f procfile.dev
3 go to https://localhost:3000/plugins/social-feed/standalone?id
4 open VS code with powr_outlet repo
5 click on debug button (crossed bug on the left)
You launch.json file should have this lines:
{
`// Use IntelliSense to learn about possible attributes.`
`// Hover to view descriptions of existing attributes.`
`// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387`
`"version": "0.2.0",`
`"configurations": [`
`{`
`"type": "node",`
`"request": "launch",`
`"name": "Launch Program",`
`"program": "${workspaceFolder}/app.js"`
`}`
`]`
}
6 click on add Configurations
choose Node.js: Attach to Process
launch.json will have next content:
{
`// Use IntelliSense to learn about possible attributes.`
`// Hover to view descriptions of existing attributes.`
`// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387`
`"version": "0.2.0",`
`"configurations": [`
`{`
`"type": "node",`
`"request": "attach",`
`"name": "Attach by Process ID",`
`"processId": "${command:PickProcess}"`
`},`
`{`
`"type": "node",`
`"request": "launch",`
`"name": "Launch Program",`
`"program": "${workspaceFolder}/app.js"`
`}`
`]`
}
7 on VS code terminal run:
npm run dev
8 choose social_feed.js to debug
if you want the server to make API call everytime to INSTAGRAM or any other feeds so that you are not working with cached data, make sure to comment out lines
if (cached.isCached && !configuration.noCache) {
`if (typeof cached.reply.errors === 'undefined' || cached.reply.errors.length > 0){`
`cached.isCached = false;`
`apiCall(feed,opts);`
`}else{`
`return callback(cached.reply);`
`}`
`} else {`
`apiCall(feed,opts);`
`}`
just leave uncommented next line: apiCall(feed,opts);
9 then you can click on the very left side of the file so that you get red dot => meaning you wanna add breakpoint here and add debugger;
10 On the top left near DEBUG instead of Launch Program choose Attach by Process ID from the drop-down and click PLAY green button and choose any suggested process id
11 Make sure that on very bottom it states: Auto Attach: On
12 go back to the browser and retype lady gaga again
13 process will stop (if it doesn't stop take next steps again: restart foreman at powr and run again npm run dev at powr_outlet, click again on Attach Process, type "ladygaga" at standalone again) and on DEBUG console you should be able to debug your program, for example, you could type
opts
which will return next data:
facebookFeedType:""
following:"ladygaga"
limit:"6"
pageName:"ladygaga"
type:"instagram"
14 on the top right corner you will see play replay and stop buttons which has the same functionality that is available on chrome console
15 don't forget to uncomment cached data