Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
113
rated 0 times [  116] [ 3]  / answers: 1 / hits: 20954  / 11 Years ago, tue, april 2, 2013, 12:00:00

I am new at Node, I have this simple Node.js server works on windows



Server Code



var ws = require(websocket-server);

var server = ws.createServer();

server.addListener(connection, function(client){
console.log(new connection);
client.send(aaaaaa);
client.addListener(message, function(msg){
console.log(msg);
});
});

server.listen(8080);


I just want to call windows API insted of line



console.log(msg);


is there any way to do this without using external library



any ideas?


More From » node.js

 Answers
24

I think node-ffi can help you to do that. node-ffi provides functionality for loading and calling dynamic libraries. With node-ffi you can get access to user32 (for example) lib and call their functions from node.js.



var FFI = require('node-ffi');

function TEXT(text){
return new Buffer(text, 'ucs2').toString('binary');
}

var user32 = new FFI.Library('user32', {
'MessageBoxW': [
'int32', [ 'int32', 'string', 'string', 'int32' ]
]
});

var OK_or_Cancel = user32.MessageBoxW(
0, TEXT('I am Node.JS!'), TEXT('Hello, World!'), 1
);

[#79152] Monday, April 1, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
clarissakourtneyb

Total Points: 710
Total Questions: 89
Total Answers: 125

Location: Dominica
Member since Sat, Nov 5, 2022
2 Years ago
;