Project Mysql Connection using Javascript

Open a new folder in VSCode (a new project with no content)

(All commands below are written at the terminal bash prompt in VSCode)

Create a package.json folder with basic contents
$npm init

View what version has been installed if you want to
$ npm –version

Install express server
$ npm install express

Create a small index.js file as follows

const express = require("express");
const app = express();

app.listen(3000, () => console.log("Listening on port 3000"));

Start express server
$ node index.js

When the above is typed you’ll see ‘Listening on port 3000’ in the console.

To install ‘prettier’ code formatter
$ npx prettier –write index.js
(if prettier is not installed this will now automatically install prettier)

Now add the following line to your package.json file
“editor.defaultFormatter”: “esbenp.prettier-vscode”

Now when you save a js file it will be automatically formatted

To ensure prettier does not format specific files or a content of for example the node_modules folder, create a file

.prettierignore

In that file type:

node_modules

This will now prevent any formatting within the node_modules folder

We could get prettier to ignore all js files by typing

*.js

In the .prettierignore file

If we’re working on a team, we want everyone to be using the same version of prettier, so to do this we need to add it as a dependency to the package.json file as below

{
  "name": "jamesdatabase",
  "version": "1.0.0",
  "description": "Management of monthly budget",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "5.1.0",
    "prettier": "11.0.0"
  },
  "editor.defaultFormatter": "esbenp.prettier-vscode"
}

Leave a Reply