How to run a file of google ranking in node.js - windows

I am newbie to Node.js and I have downloaded the google ranking from github. When i try to run a file example.js, its giving me the error "Cannot find module 'jscrape'".
I even tried to install the jscrape module but its giving me error.
I found dependencies in package.json file as follows
{
"author": "Ben Buckman <ben#newleafdigital.com> (http://newleafdigital.com/)",
"name": "google-ranking",
"description": "Fetch the Google search ranking for a phrase",
"version": "0.0.1",
"homepage": "https://github.com/newleafdigital/nodejs-google-ranking",
"repository": {
"url": "git#github.com:newleafdigital/nodejs-google-ranking.git"
},
"main": "google-ranking.js",
"dependencies": {
"jscrape": "0.0.4",
"async": "~0.1.22"
},
"devDependencies": {},
"optionalDependencies": {},
"engines": {
"node": "*"
}
"scripts": {
"preinstall": "npm install jscrape"
}
}
As i am very new to node.js, Can anyone please help me in doing this.

I'd recommend visiting the actual page http://nodejs.org/ as this provides a lot of information on downloading, installing and general how to use. Along with a vast amount of documentation.
Also I am sure jScrape is a piece of software built to be used by Node. With this kind of software (Other examples include WebSockets.IO, Express) they have to be downloaded and installed using Node.

Related

Electron-builder macOS notarization problem with puppeteer library: Not all binaries are signed

I am currently struggling with notarizing my app with electron builder for macOS! The app uses puppeteer which causes the error that the ".localChromium" folder does not get signed! I already tried a lot of things but I was not able to fix this problem.
Here is my configuration for the package.json file:
"build": {
"asar": true,
"asarUnpack": "node_modules/puppeteer/.local-chromium/**/*",
"publish": [
{
"provider": "generic",
"url": "http://www.someProvider.com"
}
],
"appId": "SomeApp",
"afterSign": "notarize.js",
"mac": {
"icon": "build/logo.png",
"category": "public.app-category.productivity",
"target": [
"dmg", "zip"
],
"signIgnore": "/node_modules/puppeteer/.local-chromium/",
"gatekeeperAssess": false
}
This is just the lastest configuration I tried! (I read about the signIgnore property on a GitHub post where someone mentioned a similar problem and was able to fix it with this, but this hasn't changed anything - I tried multiple paths in case this one is a wrong expression). I also tried to set the "hardendedRuntime" property to true.
To use puppeteer-core is not an option!
These are some errors I receive - they all state that the content in the .localChromium folder isn't signed:
Does anyone know how to fix this problem?
I solved this by using puppeteer-in-electron. Just replace import puppeteer from 'puppeteer' with import puppeteer from 'puppeteer-core'. That way .local-chromium wont be included with your electron app because it will just use the chromium that is built in along with electron. You will also need to remove puppeteer from package.json

Cypress not able to recognize Xpath functions

Running Cypress and came across using xpath in Cypress and I am trying the following code in .js file.
/// <reference types = "cypress" />
describe ("Test Contact us form",()=>{
it("Should be able to submit the form", ()=>{
cy.visit('some url');
cy.xpath('//a[contains (#href, "contact")]').click();
});
})
This is how my xpath node_modules directory path looks like
\Projects\node_modules\xpath
Here is my index.js
// Alternatively you can use CommonJS syntax:
// require('./commands')
require('xpath')
Here is my package.json
{
"name": "projects",
"version": "1.0.0",
"description": "test",
"main": "index.js",
"scripts": {
"test": "Thisistest"
},
"author": "",
"license": "ISC",
"devDependencies": {
"cypress": "^5.2.0",
"xpath": "0.0.29"
}
}
Here is a snippet of the package-lock.json
"xpath": {
"version": "0.0.29",
"resolved": "https://registry.npmjs.org/xpath/-/xpath-0.0.29.tgz",
"integrity": "some key",
"dev": true
},
After running the test, I am getting the following compilation error.
Its a TypeError.
cy.xpath is not a function
Seems to be a small config thing. However, followed the exact steps as given on https://github.com/cypress-io/cypress-xpath#readme
I removed and re-setup cypress and xpath again using npm through git bash and it worked.
Previously, I had setup using node.js command prompt. After installing xpath using same npm command, xpath was successfully downloaded, however, the directory name inside node_modules was just xpath instead of cypress-xpath. Now, even though I had require('xpath') under the index.json file, it was still unable to detect xpath.
[Updated for Cypress Ver- 10.9.0 in year 2022]
Use link below to install: cypress-xpath plugin
https://www.npmjs.com/package/cypress-xpath
Step 1: Install XPath Plugin using below command
npm install cypress-xpath
Step 2 Add this line to e2e.js in support folder
require('cypress-xpath');
Step 3 Add your xpath in cy.xpath method like below:
cy.xpath("//input[#name='userName']").should("be.visible");
Please make sure to check that you're getting code intellisense like this (refer image attached), once successful installation of the cypress-xpath plugin.
I had faced the same issue.
then I changed the reference types from cypress to cypress-xpath as follows
///reference types = 'cypress-xpath'
and the problem is resolved.
This might be helpful to you.
I downloaded cypress-xpath and updated the config file with requires('cypress-xpath) and then tried and it worked

electron-builder create .dmg on windows

I want to create my electron app installer for windows, mac and linux however currectly it's only creating .exe file:
and some win-unpacked directory and some other files which I don't even know why I need because .exe file is installing my app and creating desktop shortcut and I don't even need those extra files to get app to work.
In other word - when I just copy .exe and run on other machine then it's succesfully installing therefore why I even need those other files?
So it's working correctly with windows but it does not create any files that I could run on macOS and linux like .dmg.
This is my package.json
{
"name": "screenrecorder",
"version": "1.0.0",
"description": "Electron application to record screen",
"main": "./src/js/main/index.js",
"scripts": {
"start": "electron ./src/js/main/index.js",
"compile:sass": "node-sass src/style/scss/main.scss src/style/css/output.css -w",
"build": "electron-builder"
},
"repository": {
"type": "git",
"url": "https://github.com/d0peCode/screenRecorder"
},
"build": {
"appId": "screenrecorder",
"mac": {
"category": "your.app.category.type",
"target": "dmg"
}
},
"author": "Borys Tyminski",
"license": "ISC",
"homepage": "https://github.com/d0peCode/screenRecorder#readme",
"dependencies": {
"angular": "^1.6.5",
"angular-route": "^1.6.5"
},
"devDependencies": {
"electron": "^6.0.2",
"electron-builder": "^21.2.0",
"node-sass": "^4.9.2"
}
}
And this is my log from terminal after running npm run build
C:\Users\Borys\Documents\work\screenRecorder\desktop>npm run build
screenrecorder#1.0.0 build >C:\Users\Borys\Documents\work\screenRecorder\desktop
electron-builder
• electron-builder version=21.2.0 os=10.0.18362
• loaded configuration file=package.json ("build" field)
• writing effective config file=dist\builder-effective-config.yaml
• packaging platform=win32 arch=x64 electron=6.0.6 appOutDir=dist\win-unpacked
• default Electron icon is used reason=application icon is not set
• building target=nsis file=dist\screenrecorder Setup 1.0.0.exe archs=x64 oneClick=true perMachine=false
• building block map blockMapFile=dist\screenrecorder Setup 1.0.0.exe.blockmap
Why it doesn't create macOS installer? And what are steps to make it do so?
You can not build macOS executables with Electron on Windows as it requires the Apple SDK and XCode tools. Linux works but you need to specify the format and architecture in your build configuration.
For example to build a Linux executable in AppImage format for ARMv7l CPUs you can use this configuration:
linux: {
target: {
target: 'appimage',
arch: ['armv7l']
}
}
The full documentation on Linux build options is available here.

vscode launch.json debug and open specific url

Given the following auto-generated Visual Studio Code launch.json config:
I'd like this to launch the browser to localhost:5000/swagger when I debug, but I've tried half a dozen different things and nothing works. It just opens to localhost:5000. What am I missing here? There's no general documentation (that I could find) on all of the attributes available aside from hitting Ctrl+space to see a list, which doesn't help much.
I left out my failed attempts at getting this to work how I want...
{
"name": "Launch Demo.Api",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/Demo.Api/bin/Debug/netcoreapp2.1/Demo.Api.dll",
"args": [],
"cwd": "${workspaceRoot}/Demo.Api",
"stopAtEntry": false,
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
this one also works for me on VSCode 1.39.2
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)",
"uriFormat": "%s/swagger"
},
This one works for me:
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}/swagger"
}
}
I tried the following and it seems to work
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}/swagger",
An alternative would be using VSCode 1.48 (July 2020), which adds a Debug: Open Link command:
A new Debug: Open Link command has been added to quickly debug any URL.
Previously, to debug a browser, you had to install the Debugger for Chrome extension and write a launch.json config file to debug a page.
This command allows you to debug any URL without needing additional launch configurations.
Theme: Earthsong
If you have a URL selected in your active editor, it will open that automatically.
Otherwise, VS Code will prompt you to enter a URL, pre-filling with the URL in your clipboard, if any.
You can adjust the debug configuration used in this command via the debug.javascript.debugByLinkOptions setting.
That last setting can be used for specifying the right certificate
By default we'll use a different user data dir per workspace.
You can use a "stable" directory by adding something like to your user settings:
"debug.javascript.debugByLinkOptions": {
"userDataDir": "C:/Users/user/my-user-data-dur"
}
This will then allow any flags or settings you have to stick. I'm not sure which flags you need to fiddle with to make Chrome happy, but that config should let you set them in a way that won't be reset.
And VSCode 1.50 (Sept. 2020) will improve that feature:
Adding a button to launch it directly from the Run and debug tab (instead of having to open the Palette).
Currently the Run and debug tab only proposes to create a launch.json file, or to use Node.js Debug Terminal, but now it would be simpler to propose the Open link feature directly.
It would also be great if, when the URL is filled, it is automatically saved in .vscode/settings.json, to avoid to have to fill it again every time.
See commit dc22997 as a result.
If you are debugging node project this worked for me.
launch.json in my front-end app (Angular)
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch via npm",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "npm",
"runtimeArgs": [ "run-script", "start" ],
"console": "externalTerminal"
}
]
}
package.json that contains the npm scripts
In my case since I was debugging Angular using ng serve I had to specify the --open=true argument so the browser would launch
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve --ssl --ssl-cert %APPDATA%\\ASP.NET\\https\\%npm_package_name%.pem --ssl-key %APPDATA%\\ASP.NET\\https\\%npm_package_name%.key --open=true",
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"prestart": "node aspnetcore-https"
},
So i had this issue trying to run a C# API on Linux and this is the solution that worked for me
in .vsocde/launch.json add this in the configuration property
"launchBrowser": {
"enabled": true,
// change this to your OS name, linux, osx or windows
// you also need to change the command since xdg-open only works on linux
"linux": {
"command": "xdg-open",
"args": "${auto-detect-url}/swagger/index.html"
}
}

Doesn't work on DotCloud

I trying to launch app with StrongOps on DotCloud, but information about process/app does not appear in dashboard.Locally it works fine.
API-key and APP-name passed directly in the code. Also, i try to set ENV vars (SL_APP_NAME and SL_KEY), but no result.
App name - is random string and shoudn't represent any real variable, right?
Logs. Only this
strong-agent profiling
Cluster controls unavailable.
My code
require('strong-agent').profile(KEY,APP_NAME);
My package.json
{
"name": "slovohvat",
"version": "0.0.2",
"strongAgentKey": "607dbd9b5cd4c6dd20ae05d128b63652",
"scripts": {
"start": "node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"express": "3.4.0",
"nunjucks": "0.1.9",
"socket.io": "0.9.16",
"bigint-node": "1.0.1",
"connect": "2.9.0",
"request":"2.27.0",
"node-logentries": "0.0.2",
"redis": "0.8.6",
"socket.io-clusterhub": "0.2.0",
"connect-redis": "1.4.x",
"async": "0.2.9",
"nodetime": ">=0.8.0",
"emailjs ":"0.3.6",
"strong-agent":"0.2.18",
"raygun": "~0.3.0"
},
"repository": "",
"author": "",
"license": "BSD"
}
And my dotcloud.yaml
www:
type: nodejs
approot: app
process: node app.js 0
config:
node_version: v0.8.x
smtp_server: smtp.XXX.org
smtp_port: 587
smtp_username: XX#XX.XX
smtp_password: XXX
data:
type: redis
strongloop.json exists at same dir as dotcloud.yaml and looks correct.
Please, give me any advice i should to try.
Thank you. And sorry for my English :)
You should create a strongloop.json by using the slc strongops command, it will write the config file after you login. It sounds like you might already have done that.
Note that if you have a stongloop.json, you should NOT provide any args to .profile(). The API arguments are a mechanism for fine-grained control, and for environments when you cannot deploy a config file.
Also, you should remove strongAgentKey from your package.json (it lets anyone on stackoverflow publish data to your account), and the env variables. It sounds like you are configuring strong-agent using all 4 mechanisms at the same time! Sorry about the confusion.
After clearing the redundant config, you should be able to run your app (node .). Login to your strongops console, and see the app after a few minutes as data starts coming in.
If that doesn't work, we will need more details. It might be easier to work through this over irc or email, check out our support page: http://strongloop.com/developers/forums/

Resources