i am a newby on node.js. i want to parse a xml file into json .so i am trying to use bulebutton library from https://github.com/blue-button/bluebutton.js .
first i have installed the module by command npm install bluebutton and its created a node_modules folder with bluebutton module.
now i created a test.js file with following code
var bb = require('bluebutton');
var myRecord = bb.BlueButton('./asd.xml');
console.log(myRecord);
but its gave me an error that bluebutton is not define .please help me to figureout this problem thanks
REVISED ANSWER
From bluebuttonjs.com/docs, the require statement you use would return the BlueButton object, so bb represents said object, and it would be called like so
var myRecord = bb('someFile.xml');
However you might also note that they use fs to read the file before passing it. http://www.bluebuttonjs.com/docs/#parsing-node
PREVIOUS ANSWER (for wrong module)
According to their npm docs, you need to do
var bb = require('blue-button');
https://www.npmjs.com/package/blue-button
Related
I recently installed a package w/ Bower from here: https://github.com/takuyaa/kuromoji.js/
Reading the installation on the github, I basically copied and pasted from the guide:
kuromoji.builder({ dicPath: "../bower_components/kuromoji/dict/" }).build(function (err, tokenizer) {
// tokenizer is ready
var path = tokenizer.tokenize("すもももももももものうち");
console.log(path);
});
However, I do not know what the "kuromoji" should refer to. Here is the obvious error:
Uncaught ReferenceError: kuromoji is not defined
Here is a screenshot of my directory tree:
Not sure how to properly use this.
import kuromoji from 'kuromoji'
That provides the 'kuromoji' object you're trying to reference
It seems to be a common problem with Nodejs, and i tried all the solution without success.
My require('filepath') request fail, with the error " ENOENT: no such file or directory, open "a filepath"
For example i have those folders:
i want to use action1.js and data.json into folder2 action2.js
So while require with relative path don't work (why ?):
const action1 = require('../folder1/action1.js')
const data = require('../../data/data.json')
I tried absolute path, but that do not worked too
const action1 = require(path.join( __dirname,'../folder1/action1.js'))
const data = require(path.join( __dirname,'../../data/data.json'))
What am i doing wrong ?
The code looks correct, but I suggest you check the scope of your directory.
You can try the following steps to see your directory structure from action2.js
npm install directory-tree
Inside your file add the following lines:
const dirTree = require("directory-tree");
const tree1 = dirTree('../');
console.log(tree1);
const tree2 = dirTree('../../');
console.log(tree2);
This might help you find the scope of your directory. It's not a solution, but a way of helping you debug.
Ok, i have found my problem. And it was coming from an other require on an other file. My code here was correct.
Sorry for the dumb question, be indulgent i'm noob, and thank you for the answer.
I need to include a NodeJS library manually for our config, and I downloaded this library: https://github.com/squaremo/amqp.node/
and I tried to include the library with
var amqp = require("amqp.node-master");
I ended up getting exceptions for
Cannot find module './defs'
I look in connection.js and it has this at the beginning:
'use strict';
var defs = require('./defs');
var constants = defs.constants;
var frame = require('./frame');
var HEARTBEAT = frame.HEARTBEAT;
var Mux = require('./mux').Mux;
Looking at it, I don't see any defs folder or def.js in the library. Am I missing something?
If you look at their source, you'll see that def.js is generated during build.
That means you can't install it directly from GitHub; you need to install a version that ran make.
I am new to protobuf.
I have installed npm google-protobuf.
Following is my .proto file
syntax = "proto3";
package com.sixdee;
message Student{
string name = 1;
int32 id = 2;
}
And this is how i have generated the .js file
protoc --js_out=import_style=commonjs,binary:. testproto.proto
i have pasted the resulting testproto_pb.js in my project.
I am not able to build a protobuf packet.
I have tried
var student = new Student();
student.setName("Ankith");
student.setId(24);
I get Uncaught ReferenceError: Student is not defined
I have referred link. nothing seems to work for me.
Any help is deeply appreciated.
I'm not sure what is wrong with our code. It's hard to judge without the full source code.
I used protobufjs from npm as outlined here: http://webapplog.com/json-is-not-cool-anymore/
You need protobuf library on the front-end as well.
I am not familiar with commonjs conception, so my strategy might be basically wrong..
I want to use CryptoJS.HMAC() and CryptoJS.SHA256 in titanium
I have downloaded CryptoJS v3.1.2.zip from here.
then copy all files under Resources/CryptJS/ .
then I add this last line in core.js
return C;
}(Math));
module.export = CryptoJS; //add this line
now in my app.js
var CryptoJS = require('./CryptoJS/components/core');
CryptoJS.HMAC(CryptoJS.SHA256, dateStamp, testKey, { asBytes: true});
however it shows
undefined is not a function error when I call CryptoJS.HMAC()
Can I have help?
You find a commonJS version of Crypto Js on npm: https://www.npmjs.com/package/browserify-cryptojs
Maybe you got more luck with that!
Try adding an s to export, so it becomes:
module.exports = CryptoJS; //add this line