Jump to content

How to use cocoonjs with Node.js?


kwangde7
 Share

Recommended Posts

Hello guys, 

 

I am totally new bee to HTML5 development, but have some experience in Web Dev with Node.js.

Now, I am trying to build a game that receives data from other API and use it in game. So, I built node.js server to receive data from API using MongoDB. For better performance, I want to use cocoonjs and here is the issue. Because of their parse documentation, it's hard for me to understand how to prep for files to compile using cocoonjs complier. 

 

What they says in their documentation to upload to cloud, you need to create one js file(preferably),

and zip and upload it. But I have no idea how to prepare for this. 

My server structure is like this :

 

-Package.json

-app.js

-settings.json(for clientID and secret for API communication)

-------node module

-------routes(all js file)

-------views(all jade file)

 

and all my game was built on top of one of the views file to interact with data. 

Here is the link that will show the structure clearly. I am using one of the library 

called "shakes"

https://github.com/jonezy/shakes

 

If any of you have an experience building a HTML5 game with Node.js as backend side 

and compile with cocoonjs, could you please explain how to prep all files to upload to cloud?

 

Best,

Link to comment
Share on other sites

This is probably not going to work.

 

CocoonJS acts like a browser. While it would probably understand most of the JavaScript involved, it does not have the same internal API as Node.js does. Things like require() don't exist natively in it and it wouldn't know to load the necessary node modules to get everything working correctly.

 

However, that doesn't mean you couldn't change things or even use something like Browserify to build all the browser dependencies for you. You would just have to aim at making things work as if you were going to use Chrome or Firefox instead of server-side development.

Link to comment
Share on other sites

  • 3 weeks later...

You can Split your game into two parts : Client Side and Server side. CooconJS is like a web browser with better canvas implementation so it will not understand node.js code. Rather you can create a game in a way that it only renders the game and the node.js logic is separately hosted somewhere else.

Link to comment
Share on other sites

Node.js is the server, and CocoonJS is the client. Unless CocoonJS is created/wrapped using Node.js like node-webkit, which isn't, you can't. A clear understanding between front-end code and back-end code would help you on determining your project structure. This means you may want to separate your project between your Node.js + MongoDB server-side application and your client-side JavaScript application wrapped using CocoonJS, especially when you are talking about API.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...