Error: Cannot find module 'zeparser' - node.js

I have node.js successfully installed. I have created the file
var http = require('http');
var url=require('url');
var fs=require('fs');
var io = require('socket.io');
http.createServer(function (req, res) {
fs.readFile('/var/www/nodeJS/client.html' ,
function ( err, data ) {
if ( err ) {
console.log( err );
res.writeHead(500);
return res.end( 'Error loading client.html' );
}
res.writeHead( 200 );
res.end( data );
});
}).listen(8124, '127.0.0.1');
io.listen(http);
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
The error occurs whenever I use the io object. Without io it works fine.
Error: Cannot find module 'zeparser'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/www/nodeJS/node_modules/socket.io/node_modules/socket.io-client/node_modules/active-x-obfuscator/index.js:1:78)
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 Module.require (module.js:364:17)
After this I have also separately installed module zeparser. My default npm installation directory seems to be /usr/local/lib/node_modules.
I have set NODE_PATH as
export NODE_PATH="/usr/local/lib/node_modules"
but get the same error.
Then I tried to copy zeparser module to /var/www/nodeJS/node_modules. Then the error changes to
/var/www/nodeJS/node_modules/socket.io/lib/manager.js:104
server.on('error', function(err) {
^
TypeError: Object #<Object> has no method 'on'
at new Manager (/var/www/nodeJS/node_modules/socket.io/lib/manager.js:104:10)
at Object.exports.listen (/var/www/nodeJS/node_modules/socket.io/lib/socket.io.js:78:10)
at Object.<anonymous> (/var/www/nodeJS/app.js:35:4)
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:903:3

On your root project, do:
$ sudo npm install zeparser
It resolved the problem for me.

Related

gulp + mocha + typescript unit test

I have an error when I create new instance on test file.
This is my test:
/// <reference path="../typings/globals/mocha/index.d.ts" />
import Person from '../src/person/person';
describe('Person', () => {
let person: Person;
beforeEach(() => {
person = new Person();
});
describe('getName', () => {
it('return name', () => {
});
});
});
And my gulp task:
var gulp = require("gulp");
var ts = require("gulp-typescript");
var mocha = require("gulp-mocha");
var tsProject = ts.createProject("./tsconfig.json");
gulp.task('watch', function () {
gulp.watch('./src/**/**/*.ts', ['ts']);
});
gulp.task('ts', function () {
return tsProject.src()
.pipe(tsProject())
.js.pipe(gulp.dest("dist"));
});
gulp.task('test', function () {
return gulp.src('./tests/*.spec.ts',
{
base: '.'
})
/*transpile*/
.pipe(tsProject())
/*flush to disk*/
.pipe(gulp.dest('.'))
/*execute tests*/
.pipe(mocha())
.on("error", function(err) {
console.log(err)
});
});
gulp.task("default", ['watch', 'ts']);
So, when I launch the test an error occured, but if I comment person = new Person() then everything works.
Somebody knows what I am doing wrong?
EDIT:
Sorry, this is the error:
module.js:472
throw err;
^
Error: Cannot find module '../src/person/person'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Users/emesislol/projects/persons/tests/person.test.js:4:21)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at /Users/emesislol/projects/persons/node_modules/mocha/lib/mocha.js:222:27
at Array.forEach (native)
at Mocha.loadFiles (/Users/emesislol/projects/persons/node_modules/mocha/lib/mocha.js:219:14)
at Mocha.run (/Users/emesislol/projects/persons/node_modules/mocha/lib/mocha.js:487:10)
at Object.<anonymous> (/Users/emesislol/projects/persons/node_modules/mocha/bin/_mocha:459:18)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:420:7)
at startup (bootstrap_node.js:139:9)
at bootstrap_node.js:535:3

mosca: SyntaxError: Unexpected identifier

I was trying to run a MQTT server in nodejs on Ubuntu 14.04 LTS
var mosca = require('mosca')
var settings = {
port: 1883,
persistence: mosca.persistence.Memory
};
var server = new mosca.Server(settings, function() {
console.log('Mosca server is up and running')
});
server.published = function(packet, client, cb) {
if (packet.topic.indexOf('echo') === 0) {
return cb();
}
var newPacket = {
topic: 'echo/' + packet.topic,
payload: packet.payload,
retain: packet.retain,
qos: packet.qos
};
console.log('newPacket', newPacket);
server.publish(newPacket, cb);
}
it is throwing following error:
/home/ubuntu/node_modules/mosca/node_modules/qlobber/lib/qlobber.js:227
for (w of st.keys())
^^ SyntaxError: Unexpected identifier
at Module._compile (module.js:439:25)
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 Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/home/ubuntu/node_modules/mosca/node_modules/qlobber/index.js:3:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
Can anyone help what is that I am doing wrong?
of is a keyword in the newer ECMAScript spec, so it appears that the qlobber module used by mosca requires something newer than nodejs 0.10.x

Lab returns error no method 'experiment'

I am writing the test code for a function that will check for the existence of a username in twitter. I am using the Hapi framework and Lab for testing.
When I run npm test I get the following error:
> NameGen#0.0.0 test /Users/mario/projects/NameGen
> ./node_modules/lab/bin/lab -c
/Users/mario/projects/NameGen/test/test.js:5
Lab.experiment( "Test Username Existence", function() {
^
TypeError: Object #<Object> has no method 'experiment'
at Object.<anonymous> (/Users/mario/projects/NameGen/test/test.js:5:5)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js [as origLoader] (module.js:474:10)
at Object.require.extensions..js (/Users/mario/projects/NameGen/node_modules/lab/lib/coverage.js:32:26)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /Users/mario/projects/NameGen/node_modules/lab/lib/cli.js:85:23
at Array.forEach (native)
at Object.internals.traverse (/Users/mario/projects/NameGen/node_modules/lab/lib/cli.js:81:19)
at Object.exports.run (/Users/mario/projects/NameGen/node_modules/lab/lib/cli.js:30:29)
at Object.<anonymous> (/Users/mario/projects/NameGen/node_modules/lab/bin/lab:3:23)
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
npm ERR! Test failed. See above for more details.
npm ERR! not ok code 0
My test code is:
var Lab = require("lab");
var server = require('../'); // require index.js
var request = require('request');
Lab.experiment( "Test Username Existence", function() {
// tests
Lab.test( "Test username exists", function(done){
var options = {
url: 'http://twitter.com/BarackObama'
};
request(options, function(error, response, body){
Lab.expect(response.statusCode).to.equal(200);
});
done();
});
Lab.test("Test username does not exists", function(done){
var options = {
url: 'http://twitter.com/jhkhksdhkjahsdfkjhasdf'
};
request(options, function(error, response, body){
Lab.expect(response.statusCode).to.equal(404);
});
done();
});
});
I have the latest version of node installed and all the necessary dependencies in my package.json file. What could be causing this error?
As #Jordonias had stated. However, when I used his example, it still did not work.
I had to change the 2nd line to:
lab = exports.lab = Lab.script()
Per the Lab docs: Test files must require the lab module, and export a test script
test.js
var Lab = require('lab');
var lab = module.exports = Lab.script();
lab.experiment( "Test Username Existence", function() {
lab.test( "Test username exists", function(done){
});
});

Socket.io in a module

I'm trying to create a chat module using socket.io. Ideally I would like to pass the port number like this:
var anotherChatApp = require("anotherChatApp")(1337);
the problem I'm having is finding the object after I've set the listen() method.
var io = require("socket.io");
function anotherChatApp(port){
io.listen(port);
}
then I don't know where it goes, because I try to access the io object:
io.sockets.on('connection', function (socket) {
//dosomething
}
and I get runtime errors:
Cannot call method 'on' of undefined
I was loving node until I started building a module.
EDIT:
var io = require("socket.io");
function MacroChat(portNo){
io = require("socket.io").listen(portNo);
}
module.exports = MacroChat;
//here is where the errors come in
io.sockets.on('connection', function (socket){
});
And the error:
TypeError: Cannot read property 'sockets' of undefined
at Object.<anonymous> (D:\wamp\www\nodejitsu\macrochat\node_modules\MacroChat\lib\macrochat.js:10:3)
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 Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (D:\wamp\www\nodejitsu\macrochat\node_modules\MacroChat\index.js:5:18)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)

runnuning echo server on Ubuntu

I followed this tutorial to install the node.js on ubuntu and installation is successful. But when i type node echo-server.js i am getting following error:
module.js:340
throw err;
^
Error: Cannot find module '../../lib/ws/server'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object.<anonymous> (/home/jci/node/joyent-node-283d735/echo-server.js:2:10)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:487:10)
echo server code:
var sys = require("util")
, ws = require('../../lib/ws/server');
var server = ws.createServer({debug: true});
// Handle WebSocket Requests
server.addListener("connection", function(conn){
conn.send("Connection: "+conn.id);
conn.addListener("message", function(message){
conn.send("<"+conn.id+"> "+message);
if(message == "error"){
conn.emit("error", "test");
}
});
});
server.addListener("error", function(){
console.log(Array.prototype.join.call(arguments, ", "));
});
server.addListener("disconnected", function(conn){
server.broadcast("<"+conn.id+"> disconnected");
});
server.listen(8000);
But lib/ws/server is missing. But where do i get it from??
I don't have web socket server in my node.js installation i guess.
Thanks
Sneha

Resources