npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-config-jsb-node

v1.0.4

Published

An eslint config for node js and typescript

Downloads

1

Readme

Voila! Eslint, Prettier, and Typescript Setup for Node.js

My settings for ESLint, Prettier, and Typescript in a Node.js project.

Need, to change things? You can easily do that as well.

Pro-Tip: Check out my eslint-config-jsb for React and Typescript projects.

How it works

  • It lints all of your js and ts code in any project subdirectories
  • It uses eslint-config-airbnb-typescript for it's underyling lint rules
  • It fixes issues and formatting errors with Prettier
  • It provides all the necessary packages, like typescript and @types/node, to run typescript in Node.js

Local setup

To set this up in your project:

  1. Ensure you are in the root project directory and that you have a package.json, then install all necessary dependencies:
npx install-peerdeps -D eslint-config-jsb-node
  1. You should now notice that your package.json is popuplated with several new dependencies.

  2. Now, create an .eslintrc.json file in your root project directory, and provide the following json:

{
  "extends": ["eslint-config-jsb-node"]
}

This will actually allow your project to leverage this config.

  1. Next, add some scripts to your package.json so you can run eslint:
"scripts": {
    "lint": "eslint .",
    "lint:fix": "eslint '**/*.{ts,js}' --quiet --fix"
}
  1. If you run npm run lint from your terminal, it will expose any issues. If you run npm run lint:fix it will quietly fix all of your javascript and typescript files in any project subdirectories.

  2. Now, you need to create a tsconfig.json file in your root project directory. This is where your typescript configuration will live. It's also how eslint will be able to work with typescript. I recommend the following as a start, but feel free to customize where needed:

{
  "compilerOptions": {
    "target": "es6", // compiles to es6
    "module": "commonjs", // compiles to commonjs modules
    "rootDir": "src", // uses all files in src for compilation
    "outDir": "dist", // outputs all files to dist
    "sourceMap": true,
    "resolveJsonModule": true,
    "lib": ["es6", "dom"], // includes these libraries at compile time
    "esModuleInterop": true // allows es6 import syntax
  },
  "include": ["**/*.ts"], // which files typescript should include in compilation, it will expect files here immediately
  "exclude": ["node_modules", "dist/*"] // dist is where your files are built
}
  1. Typescript will now expect ts files to exist in your src directory. Go ahead and create a sample file in src called index.ts:
const getFood: () => string = () => {
  return 'yummy tacos!';
};

getFood();

Working with VS Code

VS Code can be tricky with linting, especially if you have global formatting tools installed like Prettier. Let's fix that.

  1. Install the ESLint plugin in VS Code.

  2. Now, let's update some of the settings for ESLint in VS Code's settings.json file. Pull up the command palette, which is cmd shift p on mac. Then type settings json and click on Open Settings (JSON). In this file, provide the following settings:

  "editor.formatOnSave": true,
  // turn auto-save off for javascript, react, typescript and typescript react
  // these will be done through eslint
  "[javascript]": {
    "editor.formatOnSave": false
  },
  "[javascriptreact]": {
    "editor.formatOnSave": false
  },
  "[typescript]": {
    "editor.formatOnSave": false
  },
  "[typescriptreact]": {
    "editor.formatOnSave": false
  },
  // eslint to run on save
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "prettier.disableLanguages": ["js", "tsx"],
  1. Now you are all set up to auto-fix all linting errors on save in VS Code.

  2. Finally, you'll need to restart VS Code for all of the changes to take place and work effectively.

Pro-Tip: You can either quit VS Code and reopen it, or pull up the command palette and type "reload" then select "Developer: Reload Window."

Customize the settings

Want to customize the ESLint and Prettier settings even further? You can add the rules in your .eslintrc.json file. ESLint Rules go under the "rules" option. Prettier options should be nested in "prettier/prettier". Any prettier rules will overwrite the existing ones in my config, so if you want to keep the existing ones, be sure to include them. Here's an example of what you could do:

{
  "extends": ["eslint-config-jsb-node"],
  "rules": {
    "no-console": "off",
    "prettier/prettier": [
      "error",
      {
        "arrowParens": "avoid",
        "trailingComma": "es5",
        "singleQuote": true,
        "printWidth": 80
      }
    ]
  }
}

This would turn all console lint errors off (so you can use console.log). It would also add a prettier rule for omitting parens in arrow functions when possible.

Where to go from here

From here, I'd recommend installing ts-node. With this package, you can execute typescript in node with no compilation necessary.