Koa.js import x from 'y' not working - koa

I'm using PM2 to server my Koa backend. However when I use imports it serves no website / crashes. What's the work around for this? I see Koa snippets with imports all over. Node v7.6 stable.

This isn't really a Koa-specific related issue. The ES6 import/export module syntax hasn't been implemented yet in browsers or node. For now, you can just use const x = require('y'). If you want to use the import/export syntax, you will need to use something like babel which converts your next-gen JS code into code that can run.

Related

How to make graphql work on ObservableHQ?

I am using observablehq for playing around with the graphql js library.
However, I fail at importing it and observable complains about this module.
Any hint? Do we need to modify the library to make it observable friendly?
Observable has a Module require debugger for these situations; given a module name, it can often find a way to make it work. E.g., for GraphQL, it suggests using Skypack, which works for me in a notebook:
graphql = import('https://cdn.skypack.dev/graphql#15.4.0')

When using React-VR with Socket.io , I crash when importing socket.io-client

I am trying to use React-VR with Socket.io. I am crashing when I try to import socket.io-client(v2.0.4). I have to browse through examples without coming up with a solution.
Putting your socket.io calls in componentDidMount as opposed to the constructor would be the correct way of doing this I beleive.

How does your workflow looks like with react.js along with backend?

I am developing a simple CRM app using Laravel 5.2 and ReactJS. Previously I was using them independently, but now I want to try to combine them together so Laravel will be my API and front-end will be all in ReactJS.
As far as I know when my app is ready to go live I will serve my master view which includes root div, bundle.js etc.
When it comes to development part I am a little confused. I really love react hot reload, but for now I had to do a little walk around to make this works.
I run two servers side by side. Webpack-dev-server and homestead, so I am able to do calls to my API. But I also have to have additional index.html for webpack-dev-server. When i change something in my index.blade.php view I also need to change this in this index.html and this is a little bit of pain.
Is there any cool trick that I can apply to improve my workflow? If there is any example please provide me a link, because I wasn't able to find one. There are many small todo apps that doesn't really solve my problem.
PS. Currently I am using this approach https://github.com/sexyoung/laravel-react-webpack
#UPDATE
Well I think I have found an acceptable solution. I will stick with webpack server configuration that I have provided in my question (it is really great cause you can use hot reload + you api calls are redirected to backend port, so instead of localhost:8080/api/user... you call /api/user/1), but I have also developed a simple elixir extension that compiles php to simple static HTML page which solves the problem of editing two index files (we all know programmers are lazy).
var php2html = require("gulp-php2html");
var gulp = require("gulp");
var rename = require("gulp-rename");
var Task = elixir.Task;
elixir.extend("php2html", function (message) {
new Task("php2html", function () {
return gulp.src("./resources/views/index.blade.php")
.pipe(php2html())
.pipe(rename('index.html'))
.pipe(gulp.dest("./"));
})
.watch("resources/views/index.blade.php");
});
elixir(function (mix) {
mix.sass('app.scss');
mix.php2html();
});
So at the moment I have two index files:
index.blade.php in resources/views which is resolved by the router on production
index.html in root of my application folder which is used by webpack-dev-server for development
and of course now these files are sync cause of gulp watch :)
If there is any better approach let me know guys.
I have usually solved this problem (duplicated index.html/php file) using this webpack plugin: https://github.com/ampedandwired/html-webpack-plugin
The idea is the opposite of yours I think. Instead of compiling your php files into static html, you can use the HtmlWebpack plugin to output a index.tmpl.php file (or whatever extension you need) using the filename configuration option. Normally I set that path to be the templates folder of my application server.
I believe this approach is generally easier than doing the other way round.
Using this plugin has other benefits, such as automatic bundle script tags injection depending on your Webpack output config, and automatic cache-bursting file hash added to the script tag urls.

Parse Image + Parse httpRequest replacements — migrating from Parse Cloud Code to Parse Server on Node (Heroku / AWS / DO)

I found that when using the parse-node package, you can no longer use Parse.Cloud.httpRequest. I also know that Parse's Image object won't be available.
So far, I've been able to replace some Parse promises with native ones and use axios to make network requests.
However, I'm relatively new to Node, so I'm curious as to what are the most direct replacements for these, and how do I use them?
You should still be able to use Parse.Cloud.httpRequest. But axios is a great library and it's a great idea to start using it if you want to learn nodejs. When it comes to the parse-image it has to be replaced. There is a library which claims 100% compatibilty, check it out here.

How to include reactivex dependency in Cloud Code

I would like to use a 3rd party library in my cloude code. It is located here https://github.com/Reactive-Extensions/RxJS
I have downloaded the .js file and put it in my cloud/ directory and tried to import it using
var rxModule = require('cloud/rx.js');
I have had success with other libraries but for this one it just throws
Uncaught Error: This operation is not supported
when i call parse deploy
Is there another way I can include a 3rd party lib?
RX can be installed using NPM:
$ npm install rx
It can then be used as follows:
var rxModule = require('rx');
There are great instructions and samples at https://www.npmjs.com/package/rx
#Darussian, I do not know if this is still relevant but I wanted to the same thing.
From what I understand, Rx won't work in Parse Cloud Code because setTimeout() and setInterval() are not defined, and they are needed for Rx.Schedulers to work.
So, what I ended up doing was trying with other similar libraries. The one I got to work was Kefir.JS. It works similar to Rx and has some of the same methods. You may be disconcerted at first but should be able to transfer any Rx code you wanted to build to Kefir.
One thing that helped me a lot was using scan() combined with last() to emulate Rx reduce() method (which is not on Kefir by default).

Resources