npm(node package manager)

이용원·2022년 12월 5일
0

Node

목록 보기
4/5

npm 연습하기

  1. npm init package.json 파일 생성하기

2.franc & langs 설치하기

franc : https://github.com/wooorm/franc/tree/main
langs : https://github.com/adlawson/nodejs-langs

package.json 파일 dependency에 라이브러리 정보가 입력됨

3.index.js 파일에 franc와 langs를 불러옴

오류 발견

노드 버전이 달라서 오류 발생
package.json에 type:"module" 추가

require 대신 import로 사용

4.github에서 이 패키지들의 사용법을 숙지하고 사용

import {franc} from 'franc'
import langs from 'langs'

// console.log(langs.where("name", "Korean"));

const langName = franc('반갑습니다', {minLength:2}) //'kor'

const result =langs.where("3", langName)
console.log(result)
{
//     '1': 'ko',
//     '2': 'kor',
//     '3': 'kor',
//     name: 'Korean',
//     local: '한국어',
//     '2T': 'kor',
//     '2B': 'kor'
//   }
  
  
console.log(result.name);//"Korean";
  
 
  1. 앞에서 배운 process.argv[2]를 이용해서 문자열 받기
import {franc} from 'franc'
import langs from 'langs'

const input = process.argv[2];

const langName = franc(input, {minLength:2})

console.log(langName);
const result =langs.where("3", langName)

console.log(result);

0개의 댓글