node-Web3 = require('web3') displays function code instead of executing - node.js

I'm working with a -great- tutorial on Blockchain-Ethereum ( Full Stack Hello World Voting Ethereum Dapp Tutorial  ) .
I followed all the steps but when i try to execute some code with the node command I get displayed the function code instead of being executed as it should .
To be more specific , in the :
$ node
> Web3 = require('web3')
> web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
I get as result :
> Web3 = require('web3')
{ [Function: Web3]
version: '1.0.0-beta.36',
utils:
{ _fireError: [Function: _fireError],
_jsonInterfaceMethodToString: [Function: _jsonInterfaceMethodToString],
_flattenTypes: [Function: _flattenTypes],
randomHex: [Function: randomHex],
_:
{ [Function: _]
_: [Circular],
VERSION: '1.8.3',
iteratee: [Function],
forEach: [Function],
...............................
{ WebsocketProvider: [Function: WebsocketProvider],
HttpProvider: [Function: HttpProvider],
IpcProvider: [Function: IpcProvider] } }
the same happens with the second command as well . I already asked at the tutorial's comment section , but any advise is more than welcome .
Thanks!

Related

What are the succeed, fail, and done Context Methods For?

In Node.js, Amazon Lambda functions have a signature that looks like this
exports.handler = async function (event, context) {
// TODO implement
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda July 20!'),
};
return response
};
The event parameter contains information about the AWS Service Event that triggered the Lambda. The context parameter contains information about the Lambda environment itself.
The context object is documented here. Per those docs, it has a single method named getRemainingTimeInMillis and a number of properties.
However, if I log this object, I see the following
INFO {
callbackWaitsForEmptyEventLoop: [Getter/Setter],
succeed: [Function (anonymous)],
fail: [Function (anonymous)],
done: [Function (anonymous)],
functionVersion: '$LATEST',
functionName: 'july-2021-delete-after-july-31',
memoryLimitInMB: '128',
logGroupName: '/aws/lambda/july-2021-delete-after-july-31',
logStreamName: '2021/07/15/[$LATEST]e05ac24e44d6489b9f8124791b3d5513',
clientContext: undefined,
identity: undefined,
invokedFunctionArn: '...',
awsRequestId: '7852dc1a-8283-46a1-b445-e6d6187553b6',
getRemainingTimeInMillis: [Function: getRemainingTimeInMillis]
}
That is, there's three additional methods named succeed, fail, and done.
succeed: [Function (anonymous)],
fail: [Function (anonymous)],
done: [Function (anonymous)],
What are these methods for, exactly? I can take some guesses and Googling around leads to some circumstantial evidence that they're deprecated methods, but I can't seem to find any documentation on what they're meant to do or how they work.

ionic node Error: Path must be a string. Received { [String:

i have problem when try to build ionic app
this error
SyntaxError: Use of const in strict mode
i think the problem was the node version ,so i install the latest version
when i try to run : ionic build android
Error: Path must be a string. Received { [String:
'C:\\PROGRAM FILES\\NODEJS\\NO
DE.EXE']
stdout: 'C:\\PROGRAM FILES\\NODEJS\\NODE.EXE',
stderr: null,
code: 0,
cat: [Function: bound ],
exec: [Function: bound ],
grep: [Function: bound ],
head: [Function: bound ],
sed: [Function: bound ],
sort: [Function: bound ],
tail: [Function: bound ],
to: [Function: bound ],
toEnd: [Function: bound ],
uniq: [Function: bound ] }
and when i try to run : cordova plugin add cordova-plugin-whitelist
Error: Path must be a string. Received { [String: 'D:\\PHONE GAP\\PROJECTS\\RENT
CLUB\\PLATFORMS\\ANDROID\\CORDOVA\\VERSION.BAT']
stdout: 'D:\\PHONE GAP\\PROJECTS\\RENTCLUB\\PLATFORMS\\ANDROID\\CORDOVA\\VERSI
ON.BAT',
stderr: null,
code: 0,
cat: [Function: bound ],
exec: [Function: bound ],
grep: [Function: bound ],
head: [Function: bound ],
sed: [Function: bound ],
sort: [Function: bound ],
tail: [Function: bound ],
to: [Function: bound ],
toEnd: [Function: bound ],
uniq: [Function: bound ] }
any ideas ?
and thankyou
I will suggest to re install all the things from node here, git here, cordova and ionic.
you can check node version by command npm -v and git version by git --version
For Cordova : npm install -g cordova
For Ionic : npm install -g ionic
Create app : ionic start appName blank
Goto app folder : cd appName
Add platform : ionic platform add android
Build your project : ionic build android
I hope it will work for you.

Get all network interfaces with node

How would I get all network interfaces and their IP address, mac addresses, state, and it's master interface.
os.networkInterfaces() won't work, because it doesn't report interfaces that are down, or don't have IP addresses, and it doesn't return their state (UP/DOWN/etc) or their master interface.
var shell = require('shelljs');
var interfaceCard = shell.ls('/sys/class/net');
this interfaceCard has list of all network interfaces
output will be
[ 'eth0',
'eth1',
'lo',
**stdout: 'eth0\neth1\nlo\n',**
stderr: null,
code: 0,
cat: [Function: bound ],
exec: [Function: bound ],
grep: [Function: bound ],
head: [Function: bound ],
sed: [Function: bound ],
sort: [Function: bound ],
tail: [Function: bound ],
to: [Function: bound ],
toEnd: [Function: bound ],
uniq: [Function: bound ] ]
interfaceCard=interfaceCard.**stdout**.split('\n');
interfaceCard = eth0, eth1, lo

Connecting to Cayley serving over localhost

I've followed the 'Getting Started' guide in Cayley's documentation and installed Cayley on my remote server:
Getting Started: https://github.com/google/cayley
Server OS: CentOS 7.2.1511
I've added cayley to my $PATH:
echo $PATH :
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/csse/cayley/src/github.com/google/cayley
Here is my config file at /etc/cayley.cfg
{
"database": "leveldb",
"db_options": {
"cache_size_mb": 2,
"write_buffer_mb": 20
},
"db_path": "~/cayley/src/github.com/google/cayley/data/testdata.nq",
"listen_host": "127.0.0.1",
"listen_port": "64210",
"read_only": false,
"replication_options": {
"ignore_missing": false,
"ignore_duplicate": false
},
"timeout": 30
}
I serve cayley over http by simply doing:
cayley http
and the terminal outputs:
Cayley now listening on 127.0.0.1:64210
On my main machine (Mac OSX 10.10.5 Yosemite), I've used npm to install the cayley package and written a test:
##testconnection.js
var cayley = require('cayley');
var client = cayley("137.112.104.107");
var g = client.graph;
g.V().All(function(err, result) {
if(err) {
console.log('error');
} else {
console.log('result');
}
});
However, it fails when I run it: node testconnection.js
error: Error: Invalid URI "137.112.104.107/api/v1/query/gremlin"
I'd like to connect to Cayley and modify the database from my test. I've found a great powerpoint full of Cayley information:
https://docs.google.com/presentation/d/1tCbsYym1kXWWDcnRU9ymj6xP0Nvgq-Qhy9WDmqWcM-o/edit#slide=id.g3776708f1_0319
As well as pertinent Cayley docs:
Overview Doc
Configuration Doc
HTTP API Doc
And a post on stackoverflow:
Cayley db user and password protection over HTTP connections
But I'm struggling to come up with a way to connect Cayley (on my remote machine) with my local machine. I'd like to connect with npm if possible, but am open to other options. Where am I going wrong?
Edit #1
I've appended the "http://" to my ip, so now it reads http://137.112.104.107. At that point, I solved another issue by performing
cayley init --config=/etc/cayley.cfg
as mentioned by the author here
I've also removed the listen_post and listen_port from my config file (each individually first, then both), yet have still have the same socket hang up error. Here's a printout of client from the test script:
Client {
host: 'http://137.112.104.107',
request:
{ [Function]
get: [Function],
head: [Function],
post: [Function],
put: [Function],
patch: [Function],
del: [Function],
cookie: [Function],
jar: [Function],
defaults: [Function] },
graph: Gremlin { client: [Circular], query: [Function] },
g: Gremlin { client: [Circular], query: [Function] },
write: [Function: bound ],
delete: [Function: bound ],
writeFile: [Function: bound ]
}
Your Cayley server is listening on 127.0.0.1 / localhost and therefor not reachable from another machine. To be able to reach it from a virtual machine or another computer on your network it needs to bind to an interface that is reachable.
If you configure host: 0.0.0.0 and check what is your network IP (I assume: 137.112.104.107) and connect it, it should work or you need to open it or forward the port on your firewall (depending on your network).

Commander can't handle multiple command arguments

I have the following commander command with multiple arguments:
var program = require('commander');
program
.command('rename <id> [name]')
.action(function() {
console.log(arguments);
});
program.parse(process.argv);
Using the app yields the following result:
$ node app.js 1 "Hello"
{ '0': '1',
'1':
{ commands: [],
options: [],
_execs: [],
_args: [ [Object] ],
_name: 'rename',
parent:
{ commands: [Object],
options: [],
_execs: [],
_args: [],
_name: 'app',
Command: [Function: Command],
Option: [Function: Option],
_events: [Object],
rawArgs: [Object],
args: [Object] } } }
As you can see, the action receives the first argument (<id>) and program, but doesn't receives the second argument: [name].
I've tried:
Making [name] a required argument.
Passing the name unquoted to the tool from the command line.
Simplifying my real app into the tiny reproducible program above.
Using a variadic argument for name (rename <id> [name...]), but this results on both 1 and Hello to being assigned into the same array as the first parameter to action, defeating the purpose of having id.
What am I missing? Does commander only accepts one argument per command (doesn't looks so in the documentation)?
I think this was a bug in an old version of commander. This works now with commander#2.9.0.
I ran in to the same problems, and decided to use Caporal instead.
Here's an example from their docs on Creating a command:
When writing complex programs, you'll likely want to manage multiple commands. Use the .command() method to specify them:
program
// a first command
.command("my-command", "Optional command description used in help")
.argument(/* ... */)
.action(/* ... */)
// a second command
.command("sec-command", "...")
.option(/* ... */)
.action(/* ... */)

Resources