Inspect Console Log in NodeJS Express - node.js

I am currently debugging a Nodejs Express application and I was wondering if there was a way to inspect the console log object similar to how you would do when developing web applications in Chrome or Firefox.
I.E:
var myObj = [{"hello": "world"}];
console.log(myObj);
Inspect Object:
Below is an example of a console.log() I am trying to inspect from Express:

Check out node-inspector to debug your Node.js script in a browser.
Here's a link to a video showing how to use the module.

Related

How can I see the response to an HTTP request made from the main process in an Electron app?

I have an Electron app that makes an HTTP request in the main process that is erroring. I want to figure out what's going wrong but I can't figure out any way to see the actual response of the request. I'm using a google api library and I can't figure out how to inspect it directly. I was hoping there'd be a way to view HTTP requests like the newtork tab in chrome devtools. When unning the program with electron --inspect-brk the error only prints the my shell console and not the devtools console, so that's of no use either. I tried downloading wireshark but I'm not very familiar with it and haven't been able to get it to work.
If you need to send your results object to the devtools you could use webContents.send in the backend and ipcRenderer in the front.
In the backend:
yourBrowserWindowVariable.webContents.send('debugging', httpRequestResults)
In the frontend:
<script>
require('electron').ipcRenderer.on('debugging', (event, message) => {
console.log('debug message', message)
})
</script>
Here's the reference in the electron docs:
https://www.electronjs.org/docs/api/web-contents#contentssendchannel-args

testcafe issue when returning from a Node ExpressJS redirect

I'm currently testing a React front-end application with TestCafe. Current environment is:
React: 16.3.2
Node: 8.10.0
TestCafe: 0.23.0
MacOS Mojave 10.14.1
We've written about 65 tests which all run great. We've introduced a Single Sign On component into our application which has posed some automation challenges. Instead of trying to drive TestCafe against our app AND this particular SSO provider, we're using a fake API call instead.
Simplified order of operations for the app during normal usage is:
React app starts, detects no SSO credentials
Environmental service provides app with a proper SSO URL, react app redirects user to SSO login page using window.location
User logs in and SSO redirects back to our react app with a an additional URL query param & respective value.
React app proceeds forward in a 'logged in' state
Pretty basic stuff.
When the React app is being tested, we just provide different URLs which point to a local ExpressJS instance on localhost:3002. When the React app performs a window.location to the fake SSO API (http://localhost:3002/fakeOAuth) the ExpressJS instance simply performs a response.redirect(http://localhost:3000/?sso=fakeCode) and now we are back to our React app with the additional synthetic SSO data. This scheme works great when not being driven by TestCafe.
When we drive the React app via TestCafe, TestCafe hangs when returning back from the fake SSO call to the React app. After this hang, we have to forcefully kill TestCafe on the command line with a ctrl-c.
Using chrome debug tools and looking at the console output, there is a message:
Uncaught TypeError: __get$ is not a function
at hotCreateRequire (bundle.js:73)
at bundle.js:719
at bundle.js:722
and a screenshot can be found at the end of this post below.
The Test code:
import { Selector } from 'testcafe'
fixture 'Landing Page Body Tests'
.page 'localhost:3000'
test ('Displays correct main welcome title', async t => {
const landingPage = Selector('.card-title')
await t
.expect((landingPage).innerText).eql('Welcome, Fakeuser', 'Incorrect Username Found')
})
Screenshot of TestCafe failure
Does anyone have any ideas as to why TestCafe crashes? I have reworked the test a few times, researched and experimented with using TestCafe's Roles and ClientFunction classes but to no avail. Any input would be greatly appreciated.
It looks like a bug in TestCafe. The __get$function is an internal TestCafe function, and the __get$ is not a function error means that TestCafe wasn't able to process your page properly and install its internal functions in the global window object.
I suggest that you create a new bug report in the TestCafe repository, and provide a HAR report and an example that can be used to reproduce the problem.

How to disable users from being able to view app through regular browsers in express / electron app

I have an express server that serves my angular front end at http://localhost:9000
I'm using electron as a desktop client.
I want to force users to view the application through electron and only through electron. I don't want users to have the ability to browser the application through any other browser.
Is there any way to disable the ability to access the app through a regular browser?
I've attempted to find information regarding this but have come up short.
EDIT: This can only be done on the client side
You can check if the window.process object exists.
if (window.process && window.process !== undefined) {
// Likely electron
}
I don't know if it's related, but is it possible for you not to use localhost? I found that after building angular parts (with ng run build) and referencing them in electron's main.js there was no need for local server to be running (but so far I only stuffed angular's quickstart into electron shell)

How to run nightmare app in headless mode?

I have a web scraper which uses the the nightmare browser automation library. Everytime I would run my nodejs app it opens up a browser window and loads the page I am trying to scrape. But I want to run it completely in the console without any windows popping up.
The closest you are going to get is just keeping the window hidden. To do this, instantiate your Nightmare as such:
var nm = new Nightmare({show: false})
I would say "don't". Use Cheerio instead, it's built for headless HTML scraping

Browserify the node.js http server

We created a simple js file, intending to find out if http.createServer works on client browser or not:
var http = require("http")
var server = http.createServer()
server.listen(9024, function () {
console.log("demo server listening on port 9024")
})
and embedded it into a html after browserify.
Display the html in chrome, unfortunately, it always fails on line 2 on http.createServer():
"Uncaught Type Error: undefined is not a function"
We also played around with "serve-browserify" a bit without success.
We have attempted the same thing on both chrome and firefox, and on Linux and Windows. All failed.
Searching through the web, there are quite a few examples for browserify http into the browser.
They all appear to be simple invocation of browserify. However we don't seem to be able to get the same good result.
Your help will be greately appreciated.
You can't use Node.js modules in the browser. All Browserify does is bundling CommonJS modules, it does not allow you to run server side code in the browser.

Resources