Note: I am using Mac OS 10.10 Yosemite
Important Note: None of the other questions and answers have worked for me.
I am following a tutorial which will have it so that I could have a multiplayer game. There is a file, which I have to download, which has a game.js file that I need to add this code into:
Note: I correctly downloaded socket.io in the correct directory.
var util = require("util"),
io = require("socket.io").listen(80);
var socket,
players;
function init() {
players = [];
socket = io.listen(8000);
socket.configure(function() {
socket.set("transports", ["websocket"]);
socket.set("log level", 2);
});
};
init();
But when I run node game.js, I get an error that looks like this:
Note: The Robhawks-mozzilla-festival-92336f2 folder is the folder that has all of the files in it
Why is the socket.configure messing up? Also, how can I fix it?
.configure() was removed when socket.io went to version 1.0. I'm guessing that the tutorial you're following is using an older version (0.9), but you have installed 1.0.
It would be best to move your code base to 1.0, as it's the latest. Configuration should be done as part of the server initialization:
var socket = require('socket.io')({
transports : [ 'websocket' ],
...
});
More info here.
However, since you're following a tutorial it may be easier to first get things up and running using the older version of socket.io, and once you have familiarized yourself with it, move to 1.0. In that case, install the older version:
$ npm install socket.io#0.9
Looging socket.io v1.0 log-level option is removed. Thus for logging one has to start program using debug module.
install debug: npm install debug -S
then run the program: DEBUG=* node entry_file.js
Related
I started my website project in Visual Studio Code and it worked fine for days. I found out about Atom and decided to move over to it. Somehow whenever I start the dev server in Atom, each Vue component spits out:
Console output (pastebin)
"Error: "extract-text-webpack-plugin" loader is used without the corresponding
plugin"
and the webpage only renders
Cannot GET /
The dev server starts fine in Visual Studio Code but not in Atom
I had the same problem with running npm run dev from CMD on Win7.
I dont know, as I did not require this plugin anywhere explicitly and when I started this error did not occure to me.
As i also started to get this error and I already tried setting NODE_ENV=development provided by this issue report from the official repo, I tried playing around.
Finally i ended up editing the webpack.dev.conf.js adding this specific plugin to the plugins key as follows:
// File header with other Imports
var utils = require('./utils')
// ...
var ExtractTextPlugin = require('extract-text-webpack-plugin')
// Then in Module definition
module.exports = merge(baseWebpackConfig, {
// ... other keys for module
plugins: [
// .. other plugins
// .. I copied this line from the webpack.prod.conf.js
new ExtractTextPlugin({
filename: utils.assetsPath('css/[name].[contenthash].css')
}),
Well there might be better and more beautiful solutions.
This is just the one that seems to fix it for me.
As I am new to VueJs and I am only using the dev server at the moment with autoreload, other answeres might be bit more polished.
I know the title of the question looks very vague! But that's there's to it.
I installed nodejs on my production server, which had phantomjs working properly, then I installed nightmare via npm install nightmare, I can see it in node_modules, I tried the example listed by the developers on github:
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: true })
nightmare
.goto('http://yahoo.com')
.type('input[title="Search"]', 'github nightmare')
.click('#uh-search-button')
.wait('#main')
.evaluate(function () {
return document.querySelector('#main .searchCenterMiddle li a').href
})
.end()
.then(function (result) {
console.log(result)
})
Nothing happened, the script did not output anything, I simplified the script to a simple single goto, for a page on my server, the page was never called when I ran the script via node file.js
I have CentOS 6.7, phantomjs 1.1
I also tested it on a fresh CentOS 7 installation with latest version of phantomjs, same thing.
Am I missing some kind of prerequisite or something? How do I debug the issue since node script.js is not giving any output
UPDATE: Apparently the problem is, electron, which is used by nightmare 'instead of phantomjs' requires a graphical enviroment, which is why it fails to run in my enviroment.
New version of Nightmare requires electron, Not PhantomsJs. Make sure electron command is in your $PATH variable.
Install Electron
npm i -g electron-prebuilt
To debug:
DEBUG=nightmare* node script.js
Look at this Dockerfile: https://github.com/aheuermann/docker-electron/blob/master/7/Dockerfile
It s the minimal libs you need. And to start you script:
Xvfb -ac -screen scrn 1280x2000x24 :9.0 &
export DISPLAY=:9.0
DEBUG=* node src/index.js
Electron based app should no more crash
You can also try to set electron in the background without actually showing any GUI. You check if this works:
var nightmare = Nightmare({ show: false});
I am new to pouchdb and nw.js and may be this question is a little bit too simple, (sorry for my ignorance).
I am trying to to use pouchdb in a nw.js project via require() but with no luck.
According to the documentation for the pouchdb setup , under Node.js section, I dit it exactly as it says with no success.
After that I installed leveldown component into the project, and I have followed the following instructions under https://github.com/nolanlawson/pouchdb-nw github project.
So, at this point, I have already done the following:
nw-gyp configure --target=0.12.3 / in the node_modules/leveldown directory
nw-gyp build
Then, according to pouchdb.com/guides/databases.html I have:
var PouchDB = require('pouchdb');
var db = new PouchDB('kittens');
but again with no luck. In addition, by running the following:
db.info().then(function (info) {console.log(info); });
getting no response.
Note: If just include this <script src="../node_modules/pouchdb/dist/pouchdb.min.js"></script>
in the index.html file, everything works like a charm.
nw.js version: 0.12.3 /
pouchdb version: 5.2.1
What am I missing?
Did you try the demo? https://github.com/nolanlawson/pouchdb-nw-hello-world There are quite a few steps to install PouchDB correctly in NW.JS.
Edit: oh wait, yes, you did see the demo already. Maybe the issue is that LevelDOWN is incompatible with your version of NW? In my demo I was using an older version of NW than you.
Yet another option is to use the websql adapter inside of Node, which should give you similar performance to LevelDB while possibly being easier to compile than LevelDOWN. If all else fails, I'd recommend filing an issue on the LevelDOWN repo; they have tons of issues related to building for X version of Node on Y architecture on Z operating system, so your combination of XYZ might be a unique one.
Finally I found a working solution to my problem.
The work-around is as follows:
1) I updated pouchDB to 5.3.0
npm update pouchdb --save
2) Then navigate to node_modules/leveldown
cd node_modules/leveldown
3) configure gyp with nw.js target version
sudo nw-gyp configure --target=0.12.3
4) Build again the nw gyp
nw-gyp build
5) And then in my javascript module file
var PouchDB = require('pouchdb');
var arincPouchDB = new PouchDB('./db/arincAirports'); // new pouch db for node without adapter // means you get leveldb adapter in this case.
var jsonData = require("../datasrc/output/data.json");
arincPouchDB.bulkDocs(jsonData);
arincPouchDB.info().then(function (info) {
console.log(info);
});
6) And the console says...
Objectadapter: "leveldb"
auto_compaction: false
backend_adapter:"LevelDOWN"
db_name: "./db/arincAirports"doc_count: 12
update_seq: 12
__proto__: Object...
Note: If you try to use pouchDB from a script tag in your html file, and at the same time you have to use it in a javascript function, that will be exported via module exports e.g
exports.pouchDBFunction = new pouchDBFunction();
and to use this exported function in another javascript file,
like this
var json2PouchDB = require("./js/pouchDBFunction.js");
json2PouchDB.pouchDBFunction;
will not work and you will get the error pouchdb is not defined. That's why you need to have pouchDB via require() function.
Hope this workaround helps...
I had a small Ember-App in just one single HTML File and everything was working fine, but since it was getting quite big I started to port it to Ember-CLI. Most things worked fine to port but I'm still struggling to add JStorage:
https://github.com/andris9/jStorage
I'm not really sure how to start as its a plain JS Lib, that I normally would just drop into the code somewhere before I use it. Now with all the modules I'm totally lost where to even start looking for how to do it.
Can anyone point me in the right direction how to use such JS Libs?
I found a few Topics around it but did not get to any working path.
Here is how I used it previously:
App.Something = Ember.Object.extend({
init: function() {
var stored = $.jStorage.get('something');
...
}
});
Well, after a lot of smoke out of my ears i got it to work:
add json2
$ bower install --save json2
This does not work out of box because there is no tags in the repo.
Edit the bower.js File to set the version to "master". Then it works.
add jStorage
$ bower install --save jstorage
Install the dependencies (not sure if necessary but i did it)
$ ember install:bower
Then the files are available in the folder bower_components, which is ignored by git and apparently my editor (atom.io) too.
Import the files in the Brockfile.js like this
...
app.import('bower_components/json2/json2.js');
app.import('bower_components/jstorage/jstorage.js');
module.exports = app.toTree();
Use it, prefixing $ with Ember not to upset JSHint (would work without)
...
var stored = Ember.$.jStorage.get(id);
...
I'm trying to run the JavaScript client for the Tumblr API but I'm getting a "require not defined" error. I've scoured almost every corner of SO trying to find a way to make it work.
I've managed to use Browserify to recognize it but at some point, I'm getting a fs.readFileSync error.
Then I tried RequireJS and again it does the require thing but I'm getting a Module name "something" has not been loaded yet for context"
I'm really new to Node.js but if I'm understanding it correctly the require() part isn't something the browser can do right? Can anyone guide me as to what solutions I can take for this? If it helps, I'm not planning to upload this on a server or anything. I'm just trying to run it on my local computer and just planning to run the API locally.
Edit:
Here's what I have on my main.js
var tumblr = require('index.js');
var client = tumblr.createClient({
consumer_key: '<consumer key>',
consumer_secret: '<consumer secret>',
token: '<token>',
token_secret: '<token secret>'
});
// Show user's blog names
client.userInfo(function (err, data) {
data.user.blogs.forEach(function (blog) {
alert('dang');
});
});
When I try requirejs, I do this to reference it <script data-main="script/main" src="scripts/require.js"></script>
It seems to me that you might be confusing server-side JavaScript (Node) and client-side JavaScript (in the browser). The Tumblr API you're trying to use is for Node only; you can't run it in a browser. You have to:
Install NodeJS and NPM on your system
npm install tumblr.js
Run the script with node <script name>
Start with the Tumblr.js example script, then customize for your own purposes!