2

I am using Deployd (deployd.com) to create an API easily. I want to create a HTML file on post event. The problem is that it doesn't work because "require" is not defined. I think that it's because the Node.js API is not accessible from Deployd. The documentation related is here: http://docs.deployd.com/docs/collections/adding-logic.md, and it says: "Events allow you to add custom business logic to your Collection. By writing Events, you can add validation, relationships, and security to your app. Events are written in JavaScript (specifically, the ECMAScript 5 standard) and have access to the Collection Events API."

So, is there a way to have access to the Node.js API or, alternatively, any way to create a file with Deployd?

Thanks!!!

user2047330
  • 119
  • 1
  • 9
  • js can only use the objects provided by the host, and if that doesn't included require, you're stuck without these low-level tools taht cannot be replaced by drop-in code. – dandavis Jul 06 '13 at 19:45
  • OK, I see what you mean, but there might be a way to solve that. Maybe by editing Deployd itself (the node.js module, I mean) or by calling the node.js API through a javascript function (like we do when we call a backend PHP function from the client-side Javascript, I mean). Please excuse me if I am wrong. – user2047330 Jul 06 '13 at 20:57
  • the node.js api you would call is require... – dandavis Jul 06 '13 at 23:28
  • Yep... I've read that Deployd has Socket.IO built-in. Could be this a way to go? – user2047330 Jul 07 '13 at 15:31

1 Answers1

2

You can enable require() in event scripts by adding the following gist to the node_modules directory: Exposing Require

But I believe the best way to do it is to create your own custom resource type. That way, you won't be restricted by what can only be done inside event scripts.

yoneal
  • 313
  • 1
  • 10
  • Great answer! Thanks! Before reading it, I decided to try creating a module, and I could create the file. The problem was that I could't get the ID of the current post (because the file to create has to have as name the ID of the post which is being created). Any ideas? Now, I gonna try also the gist. I hope I'll be able to get the ID – user2047330 Jul 10 '13 at 18:57
  • Sorry, I'm not sure how one would get the ID of a Post using modules. But if you don't need a Collection, you can store the object yourself.. – yoneal Jul 12 '13 at 08:14
  • It's OK, I did by using your module and on post event coding: this.id – user2047330 Jul 12 '13 at 12:59