WebStorm autocomplete with NodeJS and Koa js - node.js

It may sounds like a joke, but I'm really demoralized with several things about Autocomplete in WebStorm.
When I try to put Generator-function into koajs use method, I get error.
There is no autocomplete with Koa JS methods.
I tried to fix problem with TypeScript-definitions, but It is not work.
But if I create Koa instance with new, autocomplete will appears.
But another problem appears.
This code works good, but I'm demoralized with these errors and can't write my project.... :( Help me!
P.S. I have set ES6 standard in JavaScript settings.

Related

How to debug a serverless framework plugin?

I've searched throughout google about this question and I had no success...
I want to work on a serverless plugin fix, but I don't know how to attach the process to debug the code.
Currently, I'm using vscode and the plugin was developed using nodejs + typescript.
Does anyone have any tip or article explaining how to do that?
As every other process, that you want to debug, you need to run it and somehow connect the debugger to it.
You need to remember, that Serverless Framework is written in JS/TS, so it runs in Node.js. So you can debug it quite easily, if you are developing your Lambdas in Node.js, as it's quite common environment.
How to do it using Jetbrains/Webstorm/IntelliJ
Go to your node_modules directory and find the source code of the plugin, that you want to debug.
In the source code place the breakpoint.
Now Create a new "Run configuration" in IDE for NPM, that should be similar to mine:
4. Make sure you've chosen the correct package.json!
5. Now simply start debugging, like you normally do, but choose the run configuration, that you've just created.
In my example I'm using package script from package.json, but it could be also any other script, that triggers serverless deploy or serverless print in the end.
And that's it! Breakpoints should be triggered normally, like when you debug your own JS code.

Can't seem to get autocomplete to work in WebStorm

I'm having trouble getting autocomplete of basic attributes and methods working in Node.js for WebStorm. This is what it looks like:
This is what it should look like: (VSCode)
Does anyone have any idea on how to fix this? Thanks.
It's fixed in 2019.1:
You can try downloading the EAP from https://intellij-support.jetbrains.com/hc/en-us/community/topics/200367229-WebStorm?sort_by=recent_activity

Using nodejs in the browser?

Following my first question, I realized that the reason I couldn't get anything to work was that I was trying to use the require() method in the browser. In learning that this is not how Node works, I was confused. I understand now that Node is only a run-time environment that allows the use of JavaScript within the console. However, I'm still left with the question of how to achieve the functions of Node within the browser. (i.e. creating a button in the browser that creates a file using Node.) I've installed Browserify but I cannot find a good tutorial on how to use it. I'm very new to Computer Science so please forgive me for the redundant questions. Thanks a lot.
Things do change. Apparently it will be possible to use node.js in the browser soon. You might be interested in this: Run Node.js in the browser
Node as you made the point is server-side runtime environment for js and the browser is client-side. Node.js has many useful built-in functionalities and they are not accessible in browser.
I recommend you to take a look how backend and frontend differs and how do they communicate with themselves. Then I think you will understand how to achieve creating a file by clicking a button in the browser.
Sorry I don't know anything about browserify but it would be better to learn node in cli.

How to debug a react.js library

I have been using react for about a year now and i recently wanted to delve into react-beautiful-dnd. I've built plugins for vanilla js and jQuery in the past , but i am not to sure about how to go about building a react.js plugin or even debug it. i am more interested in debugging this plugin and seeing how it works more then anything , so how exactly do i go about doing it ?
Typically with a JS plugin, its mostly one file , so a console.log inside each function would give you a clear enough understanding of why and when a certain function is triggered , how would you go about doing the same with a react.js plugin ?
There are multiple ways to debug.
node debug app.js
node-inspector
console
util
Well, I use a lot of well place console.log, console.dir and util.inspect statements throughout my code and follow the logic that way.
react-beautiful-dnd
Unfortunately there is not much documentation and do-how thing for given topic. But here is what I found helpful. you can follow this link for Quick start guide: https://github.com/atlassian/react-beautiful-dnd/issues/363
The codesandbox examples from the docs:
https://github.com/atlassian/react-beautiful-dnd#basic-usage-examples
Sample Project: https://github.com/jacobwicks/rbdnd-2-list-example
All Examples
Basic usage examples
We have created some basic examples on codesandbox for you to play with directly:
Simple vertical list
Simple horizontal list
Simple DnD between two lists
To Debug any Library:
Here's how you can debug that library. This is the most basic method.
Install it.
Check what you are using and what you need to debug.
Find that method in the node_modules.
Check if that method has any declaration in the code.
If yes put some console logs and see if they get printed on console.
Then check console for your logs.
Carry on the process of console logs until you get what you are looking for.
You have to find library's function you want to debug in node_module and console.log from there. You may need to console.log the parsed file usually found in node_module/plugin/lib or node_module/plugin/dist rather then the .jsx file in node_module/plugin/src.
How do I debug Node.js applications?.
This has quite a few answers on how you can go about debugging your react application.

IntelliJ Idea 12 Unable To Resolve Express Methods

For some odd reason, I can't seem to have code completion with the "express" object in my node.js project. Here is a screen of it.
My OS is Windows 8 and I am using IntelliJ Idea 12.11. Perhaps I need to do some extra setup? Please let me know.
#CrazyCoder got it right, it is indeed a intellij bug, as of now still unpatched, guess we have to wait =( The URL is http://youtrack.jetbrains.com/issue/WEB-6667. In the meantime, I guess I will have to live with it.
if you are on IDEA 13, you will still not get the Express methods until you use the express typescript stub
go to Javascript Libraries > Downloads and switch the combobox at the top to Typescript community stubs then type express
you should see the stub, it's also here:
https://github.com/borisyankov/DefinitelyTyped/blob/master/express/express.d.ts
if you are on Java 1.7 and haven't disabled the SNI Support you will get a handshake alert and the download will fail, go to the directory where your IDEA.exe is located and add the following line to the idea.exe.vmoptions:
-Djsse.enableSNIExtension=false

Resources