Skip to main content

Command Palette

Search for a command to run...

[WIL] package.json file & RESTful API

04/23/23

Published
[WIL] package.json file & RESTful API

WIL

Wrap-up Retrospective: What I learned

  • Created a simple blog using the Express framework

  • Implemented CRUD operations based on the principles of RESTful API

  • Learned how to use ORMs such as Mongoose and Sequelize

  • Implemented various authentication methods such as cookies, sessions, JWT, and access/refresh tokens

  • Learned about the concept of middleware in Node.js

  • Explored error handling in JavaScript Studied socket.io for real-time communication

The goal for the next week Review lectures up to

  • Review HW4

  • Learn about transactions, OOP in JavaScript, and Layered Architecture

  • Complete HW5


package.json in Node

Package.json stores the name, version, author, license, and dependencies of a Node.js project along with their version information. This file can also define commands and scripts for the project.

// package.json
{
  "name": "voyage-blog",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": { // user-defined script (command) 
    "test": "echo \"Error: no test specified\" && exit 1",
    "prestart": "node ./swagger.js",
    "dev": "nodemon app.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/Siwon-Kim/voyage-blog.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/Siwon-Kim/voyage-blog/issues"
  },
  "homepage": "https://github.com/Siwon-Kim/voyage-blog#readme",
  "dependencies": { // npm module list
    "bcrypt": "^5.1.0",
    "cookie-parser": "^1.4.6",
    "express": "^4.18.2",
    "jsonwebtoken": "^9.0.0",
  },
  "devDependencies": { // modules for development
    "nodemon": "^2.0.22",
  }
}

package-lock.json in Node

Package-lock.json file contains the precise dependency and version information for packages that npm depends on. This file is used by npm when installing or updating packages and plays a crucial role in preventing version conflicts or dependency errors.

// package-lock.json
"node_modules/express": {
      "version": "4.18.2", // exact version info
      "resolved": "https://registry.npmjs.org/express/-/express-4.18.2.tgz",
      "integrity": "sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==",
      "dependencies": {
        "accepts": "~1.3.8",
        "array-flatten": "1.1.1",
        "body-parser": "1.20.1",
        "content-disposition": "0.5.4",
        "content-type": "~1.0.4",
        "cookie": "0.5.0",
        "cookie-signature": "1.0.6",
        "debug": "2.6.9",
        "depd": "2.0.0",
        "encodeurl": "~1.0.2",
        "escape-html": "~1.0.3",
        "etag": "~1.8.1",
        "finalhandler": "1.2.0",
        "fresh": "0.5.2",
        "http-errors": "2.0.0",
        "merge-descriptors": "1.0.1",
        "methods": "~1.1.2",
        "on-finished": "2.4.1",
        "parseurl": "~1.3.3",
        "path-to-regexp": "0.1.7",
        "proxy-addr": "~2.0.7",
        "qs": "6.11.0",
        "range-parser": "~1.2.1",
        "safe-buffer": "5.2.1",
        "send": "0.18.0",
        "serve-static": "1.15.0",
        "setprototypeof": "1.2.0",
        "statuses": "2.0.1",
        "type-is": "~1.6.18",
        "utils-merge": "1.0.1",
        "vary": "~1.1.2"
      },
      "engines": {
        "node": ">= 0.10.0"
      }
    },

RESTful API

  • It is an API that follows the REST architecture.

  • It is based on the HTTP protocol.

  • Resources are identified by their URI.

  • It uses HTTP request methods (GET, POST, PUT, PATCH, DELETE).

  • It performs CRUD operations on resources.

  • It follows a client-server model and is stateless, meaning that the client and server must be developed independently, each request is handled completely by the server, and the client's state is not stored on the server.

  • Advantages: It provides benefits such as standardization and scalability of network communication, and maintainability.