Meteor leaderboard app on node-webkit - node.js

I am trying to get the meteor leaderboard app to run on Node-Webkit.
I have demeteorized it and compressed it to a .nw file but when I drop it in. I get errors:
Invalid Package There is no 'package.json' in the package, please
make sure the 'package.json' is in the root of the package.
I have read on various thread but nothing clear yet.
It seems like the demeteorized app needs to be restructured. Also need to figure out how to run the server [Locally/DDP].
Edited:
P.S. I am using the demeteorized files from the leaderboard meteor app to be able to run it in node-webkit.
What exactly I am trying to figure out here is :
how to run/init the local node(demeteorized) server and set the port.
How to set environment variables for the demeteorized app for mongodb etc.
What would be used as the
"main": ?,
"node-remote": ?
for the node-webkit package.json file.
Can someone please shed some light and if possible an example will be highly appreciated.
Thanks in advanced.
Praney :)
UPDATE:
After tinkering a bit, I added the "main": "index.html" and added index.html file to the root of the demeteorized app. This file just loads the main.js file in the browser, here:
<!DOCTYPE html>
<html>
<head>
<title>Leaderboards</title>
</head>
<body>
</body>
<script src="main.js" type="text/javascript"></script>
</html>
Now I am getting this error:
"Uncaught ReferenceError: __dirname is not defined", source:
file:///Users/Praney/projects/webkit/nw-sample-apps/leaderboards/main.js(2)
main.js
process.argv.splice(2, 0, 'program.json');
process.chdir(require('path').join(__dirname, 'programs', 'server'));
require('./programs/server/boot.js');

This isn't how demeteorizer is meant to be used.. exactly/kind of.
You would use the output bundle on your deployed server to run as your meteor app, not put it in an existing meteor app.
The package.json that you get from it is slightly different to the one that meteor-npm would use.
When you've finished your meteor app you would use demeteorizer to create an easy bundle that can run on your server. If you uploaded it and untarred it:
You would install the npm modules by cding into the bundle and running npm install
You can run the app as normal as described in the docs.
The whole purpose of demeteorizer is to nodify your app, you wouldn't need to this on the platform you made it since all the npm modules would already be working. The problem it solves is usually with cross-archs, e.g if you made your app on OS X and it uses binary npm modules and the server uses Ubuntu (not os x)
I suppose node-webkit could also do it, you would need to use the root directory of demeteorize for this (seperate from your app). You can see there's a package.json already in it, perhaps the root directory you set it to use is that of your meteor app and not the untarred output of the demeteorized app?

Related

Error running node in cloud9 IDE?

First i got the following error and i couldn't figure yet what is this about:
any idea?
The problem is that you're trying to open an HTML file with Node.js.
Node.js is supposed to run JavaScript code (typically stored in .js files) and it cannot parse your HTML file, which is why you're getting these errors.
You could try executing the files called app.js or server.js with the following commands:
node app.js
or
node server.js
Also, it seems your project (or whatever it is you're working on) has a README.md file which could help to clarify where you're supposed to start.

Cannot Get/ React JS server tutorial

Im try to do the React JS tutorial and im trying the server in node. I downloaded first, all files in https://github.com/reactjs/react-tutorial/ then I put in folder then I command prompt it. and type npm install then node server.js "Server started: //localhost:3000./
Then when I go to the localhost:3000.is said Cannot Get/ .
What's the problem?
Are you entering localhost:3000 without a period?
If you wish to learn React JS. Please install on the local machine and related module like node JS, etc.
Please have look below link for your review. May be it will help you.
React JS – Install and Setup

Angular2 throws error while use the node modules reference

I am getting error while i use the angular2 from node_modules.
How do I fix? What I missed in my html file?
Please give me a git repo for angular2 for offline development.
Edit: I missed that the console was throwing other errors, too. I use Karma to run unit tests for an angular2 app and borrowed much of my test setup from the angular2 project itself.
Karma loads the files and since I'm using them for test, I load out of node_modules. The first four must be loaded first and in this order before bringing in angular2 and other libs:
'node_modules/angular2/node_modules/traceur/bin/traceur-runtime.js',
'node_modules/es6-module-loader/dist/es6-module-loader-sans-promises.js',
'node_modules/systemjs/dist/system.src.js',
'node_modules/reflect-metadata/Reflect.js',
'node_modules/angular2/**/*.js
Then a test helper configures System:
System.config({
...
paths: {
'angular2/*': 'node_modules/angular2/*.js',
'rx': 'node_modules/angular2/node_modules/rx/dist/rx.js'
}
...
});
Hope that helps. You may want to pull the files you need into a lib directory if you're serving them with your code.

Installing a Web Server for Node.js

I'm trying to follow a book I purchased called "Pro Angular JS", and I am having trouble getting a web server pointed to the right port. So I go to the command line, run Node, and the first error I get is this, when trying to install connect:
npm should be run outside of the node repl, in your normal shell.
(Press Control-D to exit.)
Ok, fair enough. So I do as the command specifies, and I get it to install just as the user, and it ends up adding a folder called node_modules in my user root folder. Ok, seems like everything still makes sense.
Now, the book tells me to create a server.js file within the Node.js installation folder. There is no Node.js installation folder actually created on my user. I see the node_modules folder for sure. So I'm guessing the root directory of my user is where node.js was installed but maybe it's hidden or something? I believe when I used the Mac installer for Node, it said it was created at usr/local/bin. But I have no idea if that is my user on my computer, or even more root access to my computer.
Lastly, back to this server.js file...so I created it with a text editor, containing this code:
var connect = require('connect');
connect.createServer(
connect.static(".../angularjs")
).listen(5000);
And of course they want me to add this file to the directory where my Node is installed. Currently, it's sitting where my current user (user is kst001) root directory is. This is also where my node_module folder was created when I installed it using the npm install connect line in the shell. They also wanted me to create a folder called angularjs, where I would store my app, and said to place it in the root directory where node.js was installed. Once again, sitting in the root directory with everything else. Yet, when I try and fire up my test document in port 5000 (localhost:5000/test.html), I get a "could not find page" error.
Already tried using this link to solve my problem, which seems dead on for my issue, but it resolved nothing:
Node / connect issue Object function createServer has no method static
I'm using a Mac, by the way. Any ideas, guys? Any help would be much appreciated.
The reason why connect.static() does not work is that the latest major version of connect (3.x) no longer contains all of the middleware that connect was bundled with in 2.x.
The readme for connect has a list of middleware references that show you the name of the module on npm that gives you the old functionality for each middleware (e.g. static is now broken out into its own module serve-static).
I'm following the same book/example and the following works. I claim no credit, it is from another Stack Overflow answer about setting up a simple server plus the contents of a comment on the same answer (question 24346161 link to it from here: nodejs connect cannot find static)
Because I used it in exactly the same learning context (book I also purchased called "Pro Angular JS") and I have been around the houses for 3 hours trying to sort this out (yes a complete novice), I thought I would post it here.
firstly from your node installation directory
npm install serve-static
secondly, your node server.js code for a simple static server to serve your angularjs directory contents in a localhost:5000 browser window, on a Windows 7 machine should be (as at July 2015) ...
var connect = require('connect'),
serveStatic = require('serve-static');
var app = connect();
app.use(serveStatic("./angularjs"));
app.listen(5000);
I just stuck a simple index.html file in the angularjs directory to begin with containing
connection working
to test it and it worked a treat.

Including socket.io.js results in undefined 'require'

I've just started with node.js and socket.io.
I installed node.js using the windows installer, resulting in the following install path:
C:\Program Files (x86)\nodejs
I used npm to install socket.io and managed to include this in my server file, which is located in my projects folder, under
D:\projects\node\nodeserv.js
I then included the socket.io.js, which is located under the same socket.io folder, under the nodjs folder.
However, when I try to open the HTML file containing the client code, I get an error in socket.io.js stating:
Undefined reference to 'require'
Can someone help me out and see what I am doing wrong?
Make sure to check your spelling very carefully. If you can post post some code to look at, we can probably tell you the problem right away. More than likely it's a simple typo.
It sounds like you are trying to run node.js from the browser. Node.js runs on the server with the node executable. When you open the HTML file in your browser, it will execute the Javascript on it in a non node.js environment.
Apparently you need to get the socket.io.js file from the nodejs server.
So instead of an include, use an async call to get the file, like:
$.getScript('http://localhost:1337/socket.io/socket.io.js', function(){
//You can now use the io namespace
});

Resources