본문 바로가기
창고 3/[Dev] My Readme

Node js 기초 1

by 부엉이의 정보 창고 2022. 1. 12.
728x90

Client and Server interaction

Front EndInteractionBackend

event, DOM, template, routing HTTP, Ajax, JSON, RESTful Web server, template, routing, database, APIs

There a few tech combinations for Node JS, which is MERN stack.

  • MongoDB : database
  • Express : framework
  • React : UI library
  • Node JS : server

Node.js

Node Package Manager

One of the advantages to use npm is dependency control. Through package.json file, npm automatically install everything you need.

Since node modules are usually massive, installing dependency through package.json is recommended.

  • npm install => project dependency installed based on package.json
  • sharing node_modules => not recommended
npm install A -g : install A package globally, works in PC anywhere
npm install A --save : install A package and save its info in package.json for future reuse.

Package.json

A center of any Node JS project, storing the project information in a single JSON object. The information displayed is as follows

  • dependency
  • author
  • version
  • license

Noteall field names and values in JSON should be in double quotes("") and separated by comma(,). Number and boolean are okay to be not in double quotes.

{
    "name":"Jake", 
    "age" : "27", 
    "handsome" :"true"
}

Beside package.json file, there is also a package-lock.json. This file is to track every package version so that anyone can reproduce the project in future.

.env file

.env is a hidden file that you can store data that needs to be hidden such as API keys and database URI. Only you can access to this file with below syntax.

process.env.variableName

processs.env is a global Node object that defines environment variables.

  • No white space in .env file
  • Variable name is in uppercase(convention)
  • Put each variable on a seperate line
  • .env is a shell file, requiring no qutoes in variables and values.

Install dotenv package through npm to use .env file. The dotenv package loads your .env files to Node process.env global object.

// npm install dotenv --save
require('dotenv').config() // dotenv.config methods loads your .env to global Node object.

Semantic Vesioning

Package.json file follows Semantic Versioing, which is a industry standard for software versioing. Libraries and frameworks published through npm should follow below standard.

"package":"MAJOR.MINOR.PATCH"
  • MAJOR : new features added, incompatible with previous features
  • MINOR : new features added, compatible with previous features. Use caret character to get latest MINOR & PATCH => e.g. "^1.3.8"
  • PATCH : bug fixes. Use tilde character to get latest PATCH => e.g. "~1.3.8"

Require and Import

  • require : synchronous, selective
  • import : asynchronous, nonselective

 

728x90

'창고 3 > [Dev] My Readme' 카테고리의 다른 글

Understanding asynchronous Javascript  (0) 2022.01.17
Node js 기초 2  (0) 2022.01.13
몽고 DB 기초 6  (0) 2022.01.11
몽고 DB 기초 5  (0) 2022.01.10
몽고 DB 기초 4  (0) 2022.01.07

댓글


loading