How to setup WebStorm for Node.js project - javascript

i'm in trouble of setting Webstorm for MEAN app
To be honest, this is my first meeting with JS and I can't understand how to correctly get syntax highlight and IDE help
What should I do after these steps?:
Installed Webstorm
Installed Node.js
Installed Mongo DB
Now I’m really confused because of the need to install Node.js packages, #types, ECMA standarts, javascript libraries, babel library
Because...
IDE asks me to use export {something} but when I'm running it it doesn't work,
AND when I use module.exports = function f, other modules doesn't see my function, but it compiles!
Also, exports without module. doesn't work.
Am I really should install all of these things or there any other more simple ways?

Related

Uncaught ReferenceError: require is not defined?

I have downloaded node-js and I am using npm inside a folder. I have downloaded the lodash package as a dependency and it is in the node modules folder.
but when I try to use it using require() it is giving above mentioned error in the console and suggesting to use ES6 module by vs code and require is a module of common.js
I have a package.json file and lodash is listed as a dependency. I am able to run lodash in the command line using node server but not in the browser
Do we need any other package installed in order for require() function to run other than node-js?
what am I doing wrong?
I am on windows and using the latest version of node and npm
let a = require('lodash');
If VSCode is suggesting you use ES6 modules, then you may have turned on ES6 Module support in your project which overrides Node's default support for CommonJS modules.
Use
import lodash from 'lodash';
instead of require.
Re edit:
I am able to run lodash in the command line using node server but not in the browser
Well yes. If you run a program designed to work in Node.js in Node.js then it work. If you run the same program in a browser, then it won't work. Just having Node.js installed somewhere doesn't turn the browser into Node.js.
If you want to use an ES6 module in a browser then:
It must be compatible with browsers (lodash might be)
You need to use import lodash from "./url/to/lodash.js"; because browsers don't have support for resolving npm paths.
If the module isn't designed to run in browsers, then you might be able to use a tool like Webpack to bundle it up in a way that will work (but that won't work in the module depends on APIs provided by Node.js, like fs).
You can use express framework to work on NODE js
let express = require('express') ;

How can I use Crypto built-in module from Node.JS in React Native Project?

I'm working on a React Native project and I need to implement authentication, with an encrypted password.
I want to use library Bcrypt but I have an issue. Bcrypt requires the Crypto module, which was a third-part library, but now it is a built-in module in Node.js.
When I try to use Bcrypt with const bcrypt = require('bcrypt'), it throws an error :
Unable to resolve module 'crypto' from 'node_modules/bcrypt/...'
I am using :
Node.js v13.0.1
NPM v6.12.0
react-native-cli v2.0.1
react-native v0.61.3
react v16.9.0
To manage this error, I went to Node.js documentation and tried the solution to know if the Crypto built-in module is available or not but it throws the same error.
Maybe I don't understand clearly what is a built-in module, is that a module which is included into the Node.js installer, so I don't have any NPM install crypto to do?
If it is the case, does anyone have an idea about why I can't use it in my project?
I also tried the rn-nodeify module, with react-native-bcrypt and react-native-crypto, but in each case some packages weren't reached, like stream, VM, fs, etc.
Do you encountered the same problem and solved it?
Someone already answered that question here
Bcrypt is not supported in Reactjs
It's because bcrypt is written in C++.
But now they have bcryptjs, the JS version of bcrypt. You can download it here https://www.npmjs.com/package/bcryptjs.
Note that bcryptjs is slower than the C++ version - bcrypt, because "it is written in pure JavaScript and thus slower (about 30%), effectively reducing the number of iterations that can be processed in an equal time span."
I would request you to look into rn-nodeify library. It enables you to use core modules and npm modules in your react-native app.
Look into this answer rn-nodeify installation and start from Step 2.
I hope i could help you.
https://github.com/margelo/react-native-quick-crypto
I've used this lib
the fix for endian.h is to rename it to <machine/endian.h>

WebStorm 2016.3 + Electron: Unresolved function or method

I am playing around with Electron and WebStorm as part of a project preparation and I am struggling with different problems. Therefore I want to start simple by creating very basic stuff and working my way up.
So I have a very simple project setup in WebStorm and my first Electron app is running. But WebStorm keeps saying that it cannot resolve function names.
Electron and electron-prebuilt are added to the package.json and Node.js coding assistance is enabled. Therefore require('electron') is recognised correctly.
I saw the blog entry by JetBrains on how to start with Electron in WebStorm and found also another similar answer here on StackOverflow.
JetBrains' blog entry
StackOverflow answer
It is said, that one should add github-electron to the JavaScript library from the communitie-stubs repositories. But these seems outdated, as there is no github-electron anymore and all other electron entries are ambiguous.
So my question is: How to setup WebStorm for plain JS ES6 correctly, beginning by eliminating the "unresolved" messages?
So, after digging into the topic more and more and climbing the steep learning curve, I finally found the answer by myself.
Here we go:
Go to WebStorm's Preferences / Languages & Frameworks / TypeScript
Make sure Use TypeScript Service is enabled
Open up WebStorm's Terminal panel (as it will automatically point to your project's working directory) and install the type definitions for TypeScript via NPM:
npm install #types/electron
You don't need to use the --save / --save-dev tags, as the types are needed solely for WebStorm's code assistance and have no impact on your project.
You'll get a new entry inside your node_modules folder containing the type definitions.
And that's it. WebStorm does not show any unresolved function or method messages for this particular module anymore.
This works for theoretically every other module, as long as there are type definitions available. But chances are good, as there are a lot of them. Way more than what WebStorm's JavaScript library download functionality offers.
Have a nice day, everyone!
Martin
install the electron library. Since the github-electron has renamed to electron.

How to get elasticsearch.js to work without using require?

I am trying to implement elasticsearch.js in my project and when I added:
var elasticsearch = require('elasticsearch');
It broke my project and said require is not defined. I did research and saw that I would have to use a library called require.js within my project but that is changing my whole project structure just for one script.
I wanted to see if anybody knows how to call an instance without using require:
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client();
You seem to be following the instructions for using elasticsearch in a node project or using a bundling system that supports CJS modules (like browserify or webpack). If you want a script that's for a browser-only project, see the Browser Builds page.
Note that at this time, they have this note:
These versions of the client are currently experimental.
You're using a version that should be used in a node project or through a module loader/bundler. The require keyword is node specific, the browser has no idea what to do with it. Require.js would help, you can also install Rollup or Webpack which would bundle the CJS (require) dependencies and your code into one file.
Or to be simple just go to https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/browser-builds.html as Jacob said

Running node.js module (more specifically YUIDoc) in a JVM

I want to run the node.js module YUIDoc in a JVM. The reason for this is that YUIDoc is my JavaScript documentation generator of choice, and that I want to be able to run it from a maven-plugin without having to install node.js, npm and such up front.
I have looked at SprintStack but it seems a bit immature so far.
Is there another way to do this?

Categories