fragments
README.md

Fragments

How to run the various scripts (i.e., lint, start, dev, debug).

EsLint setup

-npm install --save-dev eslint
-npx eslint --init

You can also run this command directly using 'npm init @eslint/config'.
Need to install the following packages:
@eslint/create-config@0.4.3
Ok to proceed? (y) y
✔ How would you like to use ESLint? · problems
✔ What type of modules does your project use? · commonjs
✔ Which framework does your project use? · none
✔ Does your project use TypeScript? · no
✔ Where does your code run? · Node
✔ What format do you want your config file to be in? · JavaScript

After installing eslint npm and eslint extension, .eslintrc.js will be generated. Then, add lint script to package.json:

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "lint": "eslint --config .eslintrc.js \"./src/**/*.js\""
},

Run npm run lint and make sure no errors

  • npm run lint

Prettier setup

-npm install --save-dev --save-exact prettier

Create a .prettierrc file, and add the code to the file

{
  "arrowParens": "always",
  "bracketSpacing": true,
  "embeddedLanguageFormatting": "auto",
  "endOfLine": "lf",
  "insertPragma": false,
  "proseWrap": "preserve",
  "requirePragma": false,
  "singleQuote": true,
  "tabWidth": 2,
  "trailingComma": "es5",
  "useTabs": false,
  "printWidth": 100
}

Create a .prettierignore file and add node_modules/ package.json package-lock.json to ignore these files
Install the Prettier - Code Formatter VSCode Extension.

Create .vscode/setting.json and add this code to it

{
  "editor.insertSpaces": true,
  "editor.tabSize": 2,
  "editor.detectIndentation": false,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.fixAll": true
  },
  "files.eol": "\n",
  "files.insertFinalNewline": true
}

Curl and jq installation

  1. Install Curl and jq from powershell
  2. Run the server

    -node src/server.js

  3. Run curl localhost:8080 in powershell
  4. Run curl -s localhost:8080 | jq to pretty-print the JSON (NOTE: the -s option silences the usual output to CURL, only sending the response from the server to jq)

Server Startup Scripts

Install nodemon to get server reloaded whenever code changes

  • npm install --save-dev nodemon
  • npm install --save-dev cross-env

Add some scripts to package.json

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "lint": "eslint --config .eslintrc.js \"./src/**/*.js\"",
  "start": "node src/server.js",
  "dev": "cross-env LOG_LEVEL=debug nodemon ./src/server.js --watch src",
  "debug": "cross-env LOG_LEVEL=debug nodemon --inspect=0.0.0.0:9229 ./src/server.js --watch src"
}

Start server by runing one of these comman:

-npm start
-npm run dev
-npm run debug (for debugging)