Evolution of a Node.js API, Zoe.js — Workspace Setup

Adams Academy
3 min readJul 20, 2020

--

In this chapter we’re going to setup our entire workspace from Visual Studio Code to Node.js

Visual Studio Code

As the very first step we need a Visual Studio Code specific settings file under a .vscode directory. The file name is settings.json. In this file we setup the indentation which is 2 spaces.

.vscode/settings.json

{
"[javascript]": {
"editor.tabSize": 2,
"editor.insertSpaces": true
}
}

Node.js

package.json

In Node.js, projects can have metadata such as information about the project itself (for example the name of the project) or information about package dependencies. package.json describes the project metadata. We can easily create a standard package.json with the npm init -y console command.

npm init -y

Switch from CJS to ESM

ESM (ECMAScript Modules) is the standard module system what we're going to use. In order to switch from CJS (CommonJS) to ESM set type to module in package.json.

"type": "module"

And then set Node.js version to greater than or equal 12.0.0 in package.json

"engines": {
"node": ">=12.0.0"
}

ESLint

ESLint is a tool for identifying and reporting problematic patterns found in JavaScript code. It covers both code quality and coding style issues.

JavaScript Standard Style is a Style guide which enforces a standardized code style in your Javascript project. In ESLint you can setup different code style to follow. We're going to set the default code style to standard JS.

Setup ESLint

Let’s install ESLint with npm install eslint --save-dev which puts ESLint as a package dependecy into the development dependencies.

npm install eslint --save-dev

When ESLint installation is finished we need to create the ESLint configuration file:

npx eslint --init

This is an interactive configuration file builder. For Zoe.js I choose the standard JS style guide and I choose JSON format for the configuration file:

Run ESLint

In order to run ESLint on your source code you can do it via Terminal or you can use a Visual Studio Code extension. npx eslint app/** runs ESLint on all the files and subdirectories under the app directory.

npx eslint app/**

npx is a tool for executing Node.js packages. npx comes with npm from version 5.2

You can even fix ESLint findings with:

npx eslint --fix app/**

In Visual Studio Code there is an extension for ESLint.

--

--

Adams Academy

Adams Academy helps you to cut through the noise and understand programming languages, web development with simple programming tutorials.