A package manager is a tool to easily handle packages. In Node.js, the top package managers are npm and yarn.
npm is similar to pip in Python.
yarn is a package manager published by Facebook. It has convenient functions to fill in disadvantages of npm and can manage packages faster.
An error can occur if both npm and yarn are used in a project. If two different versions of a package are installed, a conflict can occur.
Package.json
is a file that manages the version of the installed packages. Other metadata, such as project name, author, or license information, can be recorded. Both npm and yarn referens Package.json.
It installs files according to my environment the node_modules
folder and SHOULD NOT be shared.
Package-lock.json
records the package versions and relationships of packages in node_modules
. When a package is installed, edited, or deleted using npm, the relationship is recorded in package-lock.json
. This can be used to record exactly what package version is being used in a project.
npm init
is used in the terminal to create package.json
. Used for a new project or package.
npm install packageName
installs a package. i
can be used instead of install
. Multiple packages can be installed using spaces.
npm install -D moduleName
installs modules only needed for the development stage.
Express.js is a web framework to quickly and convieniently create a server.
Can be installed with npm i express
.
This module provides an expansion of the http module. The default methods from the http module can be used, as well the additional methods and properties of the Express module. The Express methods are more convenient and the http module is used less.
Routing is a way to respond to the client's requests (method, address, etc.).
Router helps to easily execute a client's request and is one of the basic functions of Express.js
.
A router is usually made as the following:
router.METHOD(PATH, HANDLER);
Modules are code separated into files. It can call another module and use it.
A convention that establishes the module ecosystem. Node.js uses CommonJS by default. Imports using the require()
function and exports using module.exports
.
// Import 'express' package
const express = require('express')
// Declare function as anonymous exported function object
exports.add = function add(a, b) {
return a+b
}
// Export function add() (Not needed when function is exported as an object)
module.exports = add;
// Export function add as an object:
module.exports = {add: add};
A system started to provide a comprehensive interface in Javascript. As opposed to CommonJS
// Import 'express' package as name express
import express from 'express'
// Declare function as anonymous exported function object
export function add(a, b) {
return a+b
}
// Export function add() (Not needed when function is exported as an object)
export default add;
// Export function add as an object:
export const add = add;
Request: an object that contains the information or message sent from the client to the server
Response: an object that sends a message from the server to the client
express.json()
Middleware를 이용하여야 해당 객체를 사용할 수 있습니다.A medium (매개체) that connects applications together.
Provides a URL and interface that executes a desired function from the web application (front end). The API must get data to save it to the database or provide data from the saved database to the web application (front end).
REST (Representational State Transfer) is a software architecturefor the hypermedia system. This is an API that follows the REST architecture.
Simply put, one must understand what the API is doing by seeing the URL, Headers, Method, etc.
Everything a software manages can be described as a resource.
Refers to CRUD