Getting an error when I run NPM live-server - node.js

Here's the server I'm using, https://www.npmjs.com/package/live-server. However, when I try to use ~/.live-server.json as the configuration file, I always fail... Here's what I have in the file, and it's very simple.
{
port: "8001"
}
Then I have this error when I run live-server
undefined:2
port: "8001"
^
SyntaxError: Unexpected token p
at Object.parse (native)
at Object.<anonymous> (/usr/local/lib/node_modules/live-server/live-server.js:17:20)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
I don't know why this is happening.

Property names in JSON must be quoted (JSON is not JavaScript):
{
"port": "8001"
}

It should be:
{
"port": 8001
}
Add explanation: well, in JSON, name should always double quoted, and value should also be double quoted, except number (if you double quote a number, it becomes a string). Like this:
{
"name1": "stringValue",
"name2": aNumber
}

Related

Oracle DB connection with Node.js Getting "Error: Schema User name is not Set! Try Set Environment Variable NODE_ORACLEDB_USER."

I have installed Node JS version 12, cloned node-oracle db from github.
I have also set OCI_LIB_DIR Path as mentioned in this article.
module.exports = {
user : process.env.NODE_ORACLEDB_USER || "hr",
// Get the password from the environment variable
// NODE_ORACLEDB_PASSWORD. The password could also be a hard coded
// string (not recommended), or it could be prompted for.
// Alternatively use External Authentication so that no password is
// needed.
password : process.env.NODE_ORACLEDB_PASSWORD || abcd,
// For information on connection strings see:
// https://oracle.github.io/node-oracledb/doc/api.html#connectionstrings
connectString : process.env.NODE_ORACLEDB_CONNECTIONSTRING || "jdbc:oracle:thin:#localhost:1521/orcl",
// Setting externalAuth is optional. It defaults to false. See:
// https://oracle.github.io/node-oracledb/doc/api.html#extauth
externalAuth : process.env.NODE_ORACLEDB_EXTERNALAUTH ? true : false
};
I have created a basic connection in SQL developer, would it help.
I have installed npm in node-oracledb and also set the username, but when I try to run the command "npm test" , It gives me the error
Deeksha ~/Desktop/nodewithoracle/node-oracledb (master)
$ npm test
> oracledb#4.1.0 test C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb
> mocha --opts test/opts/mocha.opts
C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\yargs\yargs.js:1163
else throw err
^
Error: Schema User name is not Set! Try Set Environment Variable NODE_ORACLEDB_USER.
at Object.<anonymous> (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\test\dbconfig.js:48:9)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (C:\Users\850044533\Desktop\nodewithoracle\node-oracledb\test\notes.js:32:18)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\mocha.js:330:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\mocha.js:327:14)
at Mocha.run (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\mocha.js:804:10)
at Object.exports.singleRun (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\cli\run-helpers.js:207:16)
at exports.runMocha (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\cli\run-helpers.js:300:13)
at Object.exports.handler (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\cli\run.js:296:3)
at Object.runCommand (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\yargs\lib\command.js:242:26)
at Object.parseArgs [as _parseArgs] (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\yargs\yargs.js:1087:28)
at Object.parse (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\yargs\yargs.js:566:25)
at Object.exports.main (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\lib\cli\cli.js:63:6)
at Object.<anonymous> (C:\Users\Deeksha\Desktop\nodewithoracle\node-oracledb\node_modules\mocha\bin\_mocha:10:23)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
at internal/main/run_main_module.js:17:11
npm ERR! Test failed. See above for more details.
set the credential environment variables to your DB credential values before you start Node.js. The error message says NODE_ORACLEDB_USER is not set.
Alternatively you can set the values directly in your getConnection() calls:
connection = await oracledb.getConnection({ user: 'hr', password: 'welcome', connectString: 'localhost/orcl' });
But be careful of hard coding passwords.
Use a valid connection string; a JDBC connection string is not usable (Node.js is not JDBC). See the node-oracledb doc JDBC and Oracle SQL Developer Connection Strings for how to determine what to use. Based on what you posted, you should use just localhost:1521/orcl.
Save yourself some time, and read the node-oracledb installation manual, the documentation, and the examples.

installing with NPM gives out error:2406C06E:random number generator

I'm using Ubuntu server 18.04.
Every time I try to use NPM it crashes and shows the following exception:
internal/crypto/random.js:119
if (ex) throw ex;
^
Error: error:2406C06E:random number generator:RAND_DRBG_instantiate:error retrieving entropy
at Object.randomBytes (internal/crypto/random.js:54:31)
at /usr/lib/node_modules/npm/lib/npm.js:444:32
at Object.<anonymous> (/usr/lib/node_modules/npm/lib/npm.js:496:3)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at /usr/lib/node_modules/npm/bin/npm-cli.js:28:13 {
opensslErrorStack: [
'error:2406B072:random number generator:RAND_DRBG_generate:in error state',
'error:2406C06E:random number generator:RAND_DRBG_instantiate:error retrieving entropy',
'error:2406B072:random number generator:RAND_DRBG_generate:in error state',
'error:2406C06E:random number generator:RAND_DRBG_instantiate:error retrieving entropy'
]
}
Does anybody has any idea of what could be wrong?

SyntaxError when declaring a class in TypeScript

I'm getting an error when declaring a class:
// This is all on my test1.ts file content
class WDesign {
wModel: string;
wQuer: string;
}
let logWDesign = (wd : WDesign) => {
console.log(wd.wModel + " " + wd.wQuer);
}
let wd1 : WDesign;
wd1.wModel = "SDS-9985";
wd1.wQuer = "escarni";
logWDesign(wd1);
Then, to show on Node command prompt:
>node test1.ts
I get the following:
[filePath].test1.ts:3
wModel: string;
^
SyntaxError: Unexpected token :
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
Typescript ver 3.1.3
Node ver. 8.12.0
Visual Studio Code 1.28.2
You firstly have to transpile the .ts file .js by simply running the command
tsc
node test1.js
This will generate javascript corresponding to your typescript files. Node cannot directly understand typescript. You have to give it javascript code.
You can use typescript-node-starter code provided by Typescript here to save configuration hustle.
Post comments if further help is required.

TypeError: Wrong input type "String" for args

I'm trying to create a connection between nodejs and redisql i fall into problem when creating table something called TypeError: Wrong input type "String" for args
the stacktrace will be added at the end of post, i have added
const redisql = require('redisql');
const sqlClient = redisql.createClient();
sqlClient.create_table("employee", " id int , name TEXT , salary double ", redisql.print);
once i run the third command i get this stack trace
TypeError: Wrong input type "String" for args
at RedisClient.send_command.RedisClient.sendCommand (d:\BuildProjects\redisproject\node_modules\redis\lib\extendedApi.js:27:19)
at rsql_send_command (d:\BuildProjects\redisproject\node_modules\redisql\index.js:28:22)
at RedisClient.proto.CREATE_TABLE (d:\BuildProjects\redisproject\node_modules\redisql\index.js:47:5)
at new Cache (d:\BuildProjects\redisproject\app\index.js:11:15)
at Object.<anonymous> (d:\BuildProjects\redisproject\app\index.js:45:20)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (d:\BuildProjects\redisproject\index.js:1:77)
at Module._compile (module.js:649:14)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
Waiting for the debugger to disconnect...
TypeError: Wrong input type "String" for args
extendedApi.js:27
at RedisClient.send_command.RedisClient.sendCommand (d:\BuildProjects\redisproject\node_modules\redis\lib\extendedApi.js:27:19)
at rsql_send_command (d:\BuildProjects\redisproject\node_modules\redisql\index.js:28:22)
a
i followed this project link in order to build mine
have no idea why, i read deeply the code and it seems it should be okay. could someone help me ?

Node.js - Error Unexpected Identifier

I'm using ubuntu 16.04 on vagrant to run this node.js.
node version is v6.2.2.
this is my code. i try to browsing for the solution using the keyword "SyntaxError: Unexpected identifier" but no luck.
function SignalFire(ID, startingLogs) {
this.fireID = ID;
this.logsLeft = startingLogs;
}
SignalFire.prototype = {
addLogs: function(numLogs) {
this.logsLeft += numLogs;
}
lightFire: function() {
console.log("Whooosh!");
}
}
this is the error i got:
/vagrant/inheritance.js:11
lightFire: function() {
^^^^^^^^^
SyntaxError: Unexpected identifier
at Object.exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:513:28)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.runMain (module.js:575:10)
at run (node.js:348:7)
at startup (node.js:140:9)
at node.js:463:3
Can you please help me with this?

Resources