Node.js Wit.ai integration - javascript

I am learning wit.ai and going through the tutorial (https://wit.ai/docs/quickstart). Everything else went well till step 6, where it asked me to clone the node.js client and install npm. Usually, I create a separate node.js project then npm intall whatever-the-module-is then use it.
I am confused on how to use node-wit. I want to create my own node.js server which will be called by my bot to implement the business logic. Here are few questions I need help with:
Can I just create a basic node.js project, install node-wit and use it?
If I deploy my node project on heroku, where do I provide the endpoint for wit.ai to call? The tutorial does not mention anything about it.
Can I perform the business logic without using Promise or any code they have given in the node-wit tutorial?
Overall I am just confused on how the node-wit code is working.
Thanks.

1) Yes you can. Simply run npm install --save node-wit, check out the github for more infos https://github.com/wit-ai/node-wit
2) Endpoints url are set within the module. Check the lib/config.js file. You just have to specify your API key to communicate with Wit.
3) The SDK uses only promises, so you have to use them too. Two solutions here : i) master this concept, my guess is that's it's worth it since promises are very handfull ii) code your own API calls, this is not difficult (check the HTTP API doc)

Related

Why are there npm packages for Browser or Third Party API's?

I am getting to grips with vanilla JS and am trying to expand my horizons using some browser API's to make some more interesting applications. I am running Webpack, Babel and Jest on most of my packages. I am trying to establish the differences between browser API's and NPM packages.
I understand what they are individually but am unsure how they interact with each other. From my understanding :
API's of the browser are ready available for us to use which are often objects we have to instantiate to use their pre-written methods in our javascript code, they are not javascript objects but are available for us to use and like anything that is global is attached to the window object.
Third Party API's are accessible via endpoints. e.g. we can make a request to a weather API by our use typing in a city and we can use this as an argument to our asychronus request to the weather API to return some JSON to us.
I understand NPM packages like jest or webpack which are written in javascript. This allow us to install other javascript files which we can import or can be run as a standalone package in the terminal instead of having to make this functionality ourselves. There are no browser API's which allow us to do this so we call upon an NPM package. They have a purpose.
What I cant understand is packages like Axios. Does Axios build on the browser fetch API and just rename itself Axios ? Or the Payments Request NPM package? Why do we need that if we have a browser API called Payments Request ? There are even packages called Console and DOM. Why are these repeated as npm packages when we can access them anyway through the Browser ? Third Party API's I can access also all seem to have NPM packages ! What is the point of these if I can directly access the API anyway through a fetch or axios request?
On the whole I guess my question is, why are there so many NPM packages for things we can already access via a browser or third party API ? Confused.

How to use React.js and Node.js on the same repository

I've recently been having trouble with this. Is it possible to have reactjs and Parse Server(not the SDK) running and taking requests in the same node project?
If so, how?
Yes you can do it.
You can use yarn workspaces to share some packages between theses two project
You have to create two different workspaces, one for the frontend and another for the backend
Here is more information about it. They have a really nice documentation

How to implement Git in pure Javascript to create a GUI?

after searching quite a lot without findind nothing about it I'm here to ask you if there is a way to implement Git in a pure Javascript web application.
I already know about Git.js but it implements just some basic things and I also wanted to build my own library to learn more in depth about Git.
What I'm not looking for is an API or a lib that could help me.
What I'm looking for is something like:
var command = {{git commit -m "Hello world"}} // Also pure git implementation
gitExecute(command);
I'm still a junior developer and maybe this could be impossible...thanks for the reply :)
What you are asking for may be difficult to do in a browser (because you will need access to the file system to run git commands). What you may need to do is create a NodeJS server which exposes REST endpoints which can be accessed by code in the browser which provides the GUI. The NodeJS server code can run commands as needed and respond to the REST HTTP requests which can be then used by your code in the browser to show/update the GUI.
The disadvantage with this method is that you will need to run your NodeJS server on the computer which has the repository and will not work if the repo is not local to the server.
Another alternative is to use the REST APIs exposed by popular GIT providers like GitHub.
EDIT:
Come to think of it, your usecase may be a good fit for an Electron App. That will allow you to build a desktop app (with access to the filesystem and privileges to execute commands) using Javascript.
For this purpose, NodeJS is mandatory.
You could install git on your server machine, and thene execute your cmds through nodejs' child processes (DOCs)

Use Meteor without its templating library

I'm building an app that uses only Polymer to structure the frontend. As a backend I'd really like to use Meteor with their Mongo realtime database.
I only need the part of Meteor that implements the DDP prototcol and provides the Mongo API to the client. Is it currently possible to remove the rest of the client libraries? I don't need jQuery, Blaze, Tracker and so forth.
I've already tried removing meteor-platform from the project, then adding all the packages meteor-platform consists of. This results into errors like ReferenceError: Meteor is not defined. It seems like this is not supported currently.
What I then used was Asteroid which is really nice. But using it prevents me from using Meteor packages like GroundDB for example.
Reading on the Meteor website gives me the feeling that it should be possible to use only some parts of Meteor, but this doesn't work for me.
What's the best way to tackle this problem?
Edit: I've uploaded a leaderboard example with the failing setup on GitHub. Meteor.isServer is causing the error. If you comment out the server stuff it works.
You're missing two packages:
meteor add meteor underscore
The meteor package is the one that exposes Meteor.isServer.

Installing Javascript client library via npm

I am very new to Node.js (which I'm assuming this is; I'm so new that I'm not really understanding what's going on here). I'm working with a client library for a system called RJ Metrics. I'm basically tying their API in with a Volusion API in order to import data into their system from the Volusion site. The code for that all makes sense but I'm not understanding how to install it and use it.
Their documentation is here:
And I'm needing to use the Javascript library because I'm working with Volusion which is on a Windows server and there is no ASP/C# option here. It says The RJMetrics Javascript client library is available via npm: and then terminal code. After research, it appeared that this uses Node.js so I installed that on my computer and ran the npm install rjmetrics in the Terminal which succeeded. I was assuming though that I must have to log into their server and run the code in order to get it to work.
Does this require me to SSH into the server? Am I way off base and is there a way I can just include some JS files in my page? I looked at their GitHub too and all of the main files use the require() function in them which I'm gathering is a Node.js function?
Apologies if I'm way off, I'm into this up to my neck and just trying to sort it all out now.
This part of the documentation (to which you refferred) is just plain ol' javascript. though NPM is the node package manager. So if you want, it looks like you can just run this .js script in a web browser like any other.
var rjmetrics = require("rjmetrics");
client = rjmetrics.Client(api_key, client_id);
# do stuff with client
If you wanted to do it in Node, you would create a .js file on your machine with their API code inside of it doing whatever you want. Then in terminal you run the script by going "node myfile.js". A local webserver setup is all you need to create and test this.

Categories