Node.js - displaying ESLint errors in terminal like create-react-app - node.js

I'm working on a Node.js app using Express, and I want ESLint to display errors/warnings in the terminal with colors like the way "create-react-app" does.
There is a way to achieve that ?
Thanks.

Use the eslint npm package: https://www.npmjs.com/package/eslint
Follow the instructions to create a .eslintrc file. You're IDE should automatically read this and show the errors/warnings

Related

How to sort import in VSCode by using eslint-plugin-simple-import-sort?

Is it possible to sort imports (by using eslint-plugin-simple-import-sort) after applying Format Document (Shift+Alt+F) in Visual Studio Code?
Currently, it works only after running eslint --fix, but I would like to sort imports on document format.
P.S. Format document triggers prettier
So if your shortcut run prettier, I would go with prettier plugin
#trivago/prettier-plugin-sort-imports.
You can add it to your project following way:
via npm
npm install --save-dev #trivago/prettier-plugin-sort-imports
or, using yarn
yarn add --dev #trivago/prettier-plugin-sort-imports
Then, you just need to setup sort rules in your .prettierrc, e.g.:
"importOrder": ["^#core/(.*)$", "^#server/(.*)$", "^#ui/(.*)$", "^[./]"],
"importOrderSeparation": false,
And, voilà
Detailed setup is described on plugin npm page linked in first paragraph.

Vue JS Intellij setup

I am working on a Vue js application but am having difficulty getting it to run/debug within IntelliJ. I am currently running it from the command line but I'm interested in getting it to debug in IntelliJ. Not many tutorials out here on getting this set up to work. Is there anyone that has experience in setting up this framework and IDE?
Steps are rather straightforward and described in blogpost:
First, install the JetBrains IDE Support Chrome extension. This will bind the browser debugger environment with IntelliJ in real-time.
start the server with npm serve (can be done from a gutter in package.json):
create a new JavaScript debug configuration, specify the URL your app is running on (usually http://localhost:8080) in it, put the breakpoints right in the source code, and start the debug session.
See also https://blog.jetbrains.com/webstorm/2019/03/get-started-building-apps-with-vue-js-in-webstorm/ for some hints on working with Vue.js in IDEA. And https://medium.com/dailyjs/stop-painful-javascript-debug-and-embrace-intellij-with-source-map-6fe68eda8555
You can add "Run Configuration" for any project to run in Intellij. For this, you must have a run script in package.json.
Refer below link for a screenshot. NPM Run Configuration Sample:
Choose NPM and give like this. Once done, you are all ready for clicking the RUN button available in the toolbar to run the project

create nodejs cli select/options menu

How do you create an arrow-key menu list?
I'm looking for something like after entering in eslint init or create-react-app <project>? (see images below)
ESlint
yeoman
Searching around to find ways to create a CLI, I found NodeJS to be an option followed by a few tools: Commander.js, Vorpal, and/or create-new-cli.
If I am on the right track, how can I create a CLI arrow-key select menu?
I believe yeoman is using inquirer. Source: yo's dependencies.
I've also seen prompts which has a similar arrow selection feature and other cli ui/ux features. See the demos about halfway down the page.
Note: I've never actually used either, I'm just in the same research phase.
looks like 'inquirer' (npm i inquirer)
also for progress bars and such you should look at clui (npm i clui)
for parsing commands most use commander (npm commander) or the open cli framework (npm i oclif) - you can also look at yargs (very similar to commander, npm i yargs)
inquirer and clui work very well with both command parsers.
Have fun.

Why does node.js plugin in Intellij-Idea don`t work?

I installed plugin for Intellij-Idea and it doesn`t work. Why can it be? As you can see the require word doesn`t become yellow.
And here is my plugin installed:
Please make sure to enable Node.js Core library in File | Settings | Languages & Frameworks | Node.js and NPM
I like to hover over things that are underlined to give me clues as to where to start. Your "path" and "require" are underlined. Your errors might say Unused local variable 'path' and Unresolved method or function require()
You might not have installed node in the current project. If you don't have node installed, try:
npm init to create a package.json file.
IntelliJ will walk you through creating the file. You can just press enter all the way through if you want and edit it later.
npm install express --save (replace express with whatever library you are trying to use) to save library in the dependencies list
Installing express
How can I fix WebStorm warning “Unresolved function or method” for “require”

Error code: 800A1391 Source: Microsoft JScript runtime error Running Grunt - Module is undefined

New Grunt user here who is using a lot of new tools (npm nodejs) today.
I've got Grunt "installed" and have been able to create a grunt.js file using the init task as described here: http://net.tutsplus.com/tutorials/javascript-ajax/meeting-grunt-the-build-tool-for-javascript/ and here: https://github.com/cowboy/grunt/blob/master/docs/getting_started.md. But whenever I run the "grunt" command I get an error:
Windows Script Host
Script: c:\users\[]\Documents\code\grunt\grunt.js
Line: 2
Char: 1
Error: 'module' is undefined
Code: 800A1391
Source: Microsoft JScript runtime error
As explained in the FAQ, you need to type grunt.cmd instead on Windows because the OS tries to launch grunt.js
Or you can install grunt-cli globally instead. This package will run any version of Grunt if it's been installed locally to your project.
SOLVED !!
So, this problem occur because windows by default associative < *.js > files
with >>
"Microsoft Windows Based Script Host".
grunt need to open by default with (grunt.cmd).
it easy to slove, by change default app (open with..)
Guide :
Go to any javascript file with "js" extension. (any file)
Right-Click(mouse) > Properties > "Opens with:" Change...(button)
Choose Notepad ( or any javascript IDE ).
PROBLEM SOLVED ! :)
good luck
If you're getting a "Microsoft JScript runtime error" that means that node.js isn't even getting invoked; instead Windows Script Host is trying to run your code. That's probably a problem with filetype associations; IIRC Windows defaults to trying to execute a ".js" file with WSH. You may wind up having to create a shortcut to your script, specifying a command line (probably something like "node %1") and a starting directory in order to make sure that it's executed properly.
It would help if you could tell us exactly how you're trying to invoke your code.
it seems that in the latest versions of the grunt modules, you would have to do the following to have it work under windows:
remove any globally installed grunt
npm uninstall -g grunt
install grunt-cli globally
npm install -g grunt-cli
install grunt locally into your project
npm install grunt
installing grunt (v0.4.x) globally does not seem to create the necessary grunt.cmd anymore. it seems that the recommendation is now to have grunt installed locally to be able to use version-specific Gruntfiles
As Florian F suggested, running grunt.cmd works. This is because of the process Windows is looking for your grunt command.
When typing grunt -h Windows will proceed to look for the following files:
./grunt.cmd
./grunt.* (grunt.js is found in this case which is why you see "module is undefined")
%APPDATA%/npm/grunt.cmd
An alternative to using "grunt.cmd" is to use grunter which simply renames the command to grunter... then you no longer have this problem.
To answer this, first we need to understand that the error is caused because it is being executed by Windows Script Host.
Now, run the code from your cmd promt with the following syntax:
>node <application_name>.js
this will allow the Node.js application to open through V8 JavaScript engine(Google's).
P.S: Please reply back if this has helped in resolving your issue else post the problem you are facing after trying this.
I had a similar issue, the problem is file association, I would recommend:
right click on a .js file and choose open with.
then you choose nodejs/node.exe (somewhere in "program files" folder
then make tick box where it says "always open .js files " (paraphrasing)
That should do the trick.
I went through the same issue when running an old Node project.
The issue was with the name of the js file, it was node.js. So the while running the command node node.js, it was opening up a windows dialogue box.
I just changed the name of the file to app.js and the error flew away.
So, in my case i had tryed all the mentioned above with no result.
But i have fund that im dont type: node in the full sentence as the following snipet
node script.js.And remember never understimate your own miscoding.
Solution:
Go to any javascript file with "js" extension. (any file)
Right-Click(mouse) > Properties > "Opens with:" Change...(button)
Choose Notepad ( or any Javascript IDE like VS Code ).

Resources