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
Related
I am using mocha to test my node js code. While running on windows machine, I am able to test my application successfully. But when I am trying to test same application project in Ubuntu , I am getting ReferenceError: ert is not defined . So i did "rm -rf node_modes" and "npm i" again . But the issue still persist.
Error in terminal
$ npm test
> myapplication#1.0.0 test /NodeProject/MyApplication
> mocha Test/* --require #babel/register
/NodeProject/MyApplication/node_modules/yargs/yargs.js:1163
else throw err
^
ReferenceError: ert is not defined
at Object.<anonymous> (/NodeProject/MyApplication/Test/app.test.js:1:4)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Module._compile (/NodeProject/MyApplication/node_modules/pirates/lib/in dex.js:99:24)
at Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Object.newLoader [as .js] (/NodeProject/MyApplication/node_modules/pira tes/lib/index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at /NodeProject/MyApplication/node_modules/mocha/lib/mocha.js:330:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/NodeProject/MyApplication/node_modules/mocha/lib/moch a.js:327:14)
at Mocha.run (/NodeProject/MyApplication/node_modules/mocha/lib/mocha.js:8 04:10)
at Object.exports.singleRun (/NodeProject/MyApplication/node_modules/mocha /lib/cli/run-helpers.js:207:16)
at exports.runMocha (/NodeProject/MyApplication/node_modules/mocha/lib/cli /run-helpers.js:300:13)
at Object.exports.handler.argv [as handler] (/NodeProject/MyApplication/no de_modules/mocha/lib/cli/run.js:296:3)
at Object.runCommand (/NodeProject/MyApplication/node_modules/yargs/lib/co mmand.js:242:26)
at Object.parseArgs [as _parseArgs] (/NodeProject/MyApplication/node_modul es/yargs/yargs.js:1087:28)
at Object.parse (/NodeProject/MyApplication/node_modules/yargs/yargs.js:56 6:25)
at Object.exports.main (/NodeProject/MyApplication/node_modules/mocha/lib/ cli/cli.js:63:6)
at Object.<anonymous> (/NodeProject/MyApplication/node_modules/mocha/bin/_ mocha:10:23)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! Test failed. See above for more details.
And here is my app.test.js file
var assert = require('assert')
, expect = require('expect.js'),
W3CWebSocket = require('websocket').w3cwebsocket;
describe('Test Suite', function() {
var client;
beforeEach(function(done) {
client = new W3CWebSocket('ws://localhost:8091/', 'echo-protocol');
client.onopen = function() {
console.log('WebSocket Client Connected');
done();
};
client.onclose = function() {
console.log('echo-protocol Client Closed');
};
});
afterEach(function(done) {
if(client!=null){
client.close();
}
done();
});
it('My App result', (done) => {
if (client.readyState === client.OPEN) {
client.send(`"data":"dummy"}`);
}
client.onmessage = function(e) {
let data = e.data;
expect(data).to.not.equal(null);
expect(data).to.not.equal(undefined);
done();
};
});
});
I faced similar issue. It was because babel version in package.json is different from the one whose specific settings are set in .babelrc file
Try deleting .babelrc file and see if it works.
The ert probably is from
.../node_modules/babel-core/lib/transformation/file/options/option-manager.js:128
log.error or log.ert
If not search whole directory for ert, that should give you some clue
I'm trying to run a gulp based application.
On Ubuntu, everything is working, but on Debian server not.
Ubuntu: npm: 5.3.0, nodejs: v8.2.1, bower#1.8.0, gulp-cli#1.4.0, npm#5.3.0
Debian: npm: 5.3.0, nodejs: v8.2.1, bower#1.8.0, gulp-cli#1.4.0, npm#5.3.0
Gulpfile:
'use strict';
const gulp = require('gulp');
const sass = require('gulp-sass');
gulp.task('scss2css', function () {
gulp.src(['./web/scss/style.scss'])
.pipe(sass({outputStyle: 'compressed'}))
.pipe(gulp.dest('./web/css/'));
});
gulp.task('scss2css:watch', function () {
gulp.watch('./scss/**/*.scss', ['scss2css']);
});
gulp.task('default', function () {
gulp.start('scss2css');
});
When I type "gulp", I receive message like below:
module.js:487
throw err;
^
Error: Cannot find module 'camelcase'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/usr/local/lib/node_modules/gulp-cli/node_modules/yargs/lib/parser.js:3:17)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
I just removed nodejs package and directories:
/usr/lib/node_modules/
/usr/local/lib/node_modules/
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
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
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.