Cannot run Javascript code on Atom editor - javascript

Atom is not able to run javascript code for some reason, I have tried both packages such as atom runner and atom script with no success.
I have Node JS installed on my computer and javascript package installed on Atom, I have no idea why it does not work.
Here is the code which is returned after trying to run a javascript prompt.
C:\Users\artisan\Desktop\hi.js:1
(function (exports, require, module, __filename, __dirname) { var hi = prompt("wt");
^
ReferenceError: prompt is not defined
at Object.<anonymous> (C:\Users\artisan\Desktop\hi.js:1:72)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3

prompt() is a function which is implemented by Web Browsers.
In serversided JS you can't use this function.

Related

Cannot find module error for Java while executing javascript code

I'm facing the following error message on Windows 10x64 for Java module while executing javascript code:
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'java'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (C:\Users\Rau\Desktop\Test.js:1:12)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)"
var java = require('java');
var javaLangSystem = java.import('java.lang.System');
The java module is not automatically available (i.e. it is not included with node.js ). It is available through the npm registry: https://www.npmjs.com/package/java
What this error is trying to tell you is it looked in all the paths for the java module and could not find it.
Make sure you have the java module installed via:
npm install java

Why am I getting error "requires a generator function"

I installed the module "koa-cache-control" via npm.
I added the following lines to my index.js.
const cacheControl = require('koa-cache-control');
Then...
app.use(cacheControl({
noCache: true
}));
Here is the error I get when starting node.
Any clues?
AssertionError: app.use() requires a generator function
at Application.app.use
(/home/www/node_modules/koa/lib/application.js:106:5)
at Object.<anonymous> (/home/www/index.js:17:5)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
Thanks!
You seem to be using an old version of Koa. The 1.x versions used a generator-based type of middleware, which was changed to Promises in version 2.
You'll either have to update Koa or use the old version 1.0.0 of koa-cache-control.

JavaScript settings. brain js

I have downloading VS Code, downloading brain.js using npm, found example but I get this error in console all the time.
Debugger listening on ws://127.0.0.1:31661/83ca1086-743d-46cf-96bc-4bb352980d2b
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
/Users/user/Downloads/using-machine-learning-to-determine-light-or-dark/js/index.js:1
(function (exports, require, module, __filename, __dirname) { const input =
document.querySelector("input")
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
at startup (internal/bootstrap/node.js:228:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:576:3)
Waiting for the debugger to disconnect...
ReferenceError: document is not defined
index.js:1
at Object.<anonymous> (/Users/user/Downloads/using-machine-learning-to-determine-light-or-dark/js/index.js:1:77)
at Module._compile (internal/modules/cjs/loader.js:675:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
at startup (internal/bootstrap/node.js:228:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:576:3)
How can I solve it?
document.querySelector("input") leads to document is not defined. The issue: You are running browser code in your console.

Node - Unexpected or invalid token in line 1, after reinstalling Windows

I have a JavaScript file that I could run just fine yesterday. I reinstalled Windows last night, reinstalled Node this morning, and I'm trying to run the same JavaScript file now, but its giving me an error.
$ node index.js
C:\Users\<user-name>\Google Drive\Projects\<blah>-coding\index.js:1
(function (exports, require, module, __filename, __dirname) {
SyntaxError: Invalid or unexpected token
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
code is Unicode and not working, just save as UTF-8, working great!

Opal loads in Chrome but not in Node (ReferenceError: Opal is not defined)

For example, if I just run the following:
node opal.min.js
The result is:
/home/benjamin/workspace/1/opal.min.js:1
klass){return obj.toString()}else{return obj.$inspect()}})}(self)})(Opal);(fun
^
ReferenceError: Opal is not defined
at Object.<anonymous> (/home/benjamin/workspace/1/opal.min.js:1:15264)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
However, if I load opal in a page in Chrome and compile a "hello world" script, it runs just fine with no complaint. I can't figure out why this is happening. I'd really like to be able to run these scripts using Node.
Opal v0.7 has been released with explicit Node.js support.
In fact Node.js is the default runner for the CLI and there's a nodejs file in stdlib that will add a (basic) platform specific implementation of File, Dir, IO, etc. E.g.:
$ opal -rnodejs -e 'exit 127'
$ echo $?
127

Categories

Resources