Hello Friends,
Recently I have started work in Node.js for one of our project's backend development, We are using kinvey for our backend and I'm responsible for all the backend architecture & development. So in this post I'm going to show you usage of kinvey's flex sdk to create simple node service and run it.
1 - Create package
2 - Install kinvey flex sdk in you node package.
Recently I have started work in Node.js for one of our project's backend development, We are using kinvey for our backend and I'm responsible for all the backend architecture & development. So in this post I'm going to show you usage of kinvey's flex sdk to create simple node service and run it.
1 - Create package
$ mkdir helloworld $ cd helloworld $ npm init
2 - Install kinvey flex sdk in you node package.
$ npm install kinvey-flex-sdk --save
3 - To use kinvey flex module in your project add require as following.
const sdk = require('kinvey-flex-sdk');
4 - Check IP address of your work station or server.
My macbook has 192.168.1.123
5 - Write flex function code
// File : index.js const sdk = require('kinvey-flex-sdk'); sdk.service({ host: '192.168.1.123', port: 8080 }, function (err, flex) { const flexFunctions = flex.functions; // gets the FlexFunctions object from the service function helloWorldHandler(request, complete, modules) { return complete({ "message": "Hello World" }).ok().done(); } flexFunctions.register('helloWorld', helloWorldHandler); });
6 - Run service
$ node index.js $ Service listening on 8080
7 - Send request to our flex function, execute following command to see response from our node service that is written using kinvey's flex sdk.
$ curl -X POST -H "Content-Type: application/json" -d '{}' "http://192.168.1.123:8080/_flexFunctions/helloWorld"
Above command will return following json response.
{"request":{"method":"POST","headers":{},"username":"","userId":"","objectName":"","tempObjectStore":{},"body":{}},"response":{"status":0,"headers":{},"body":{"message":"Hello World"},"statusCode":200,"continue":false}}
I hope this post will help you to understand basic of kinvey flex sdk, later I will try to write some posts on advance concepts of flex sdk.
Thanks.