nodejs6 [Node.js] FCM으로 푸시 메시지 전송(단일, 여러개) 📌 선행 작업발급받은 serviceAccountKey.json 파일로 초기 세팅해주기.import admin from 'firebase-admin';import serviceAccount from 'path/to/serviceAccountKey.json';admin.initializeApp({ credential: admin.credential.cert(serviceAccount)}); 1. 단일 건 전송admin.messaging().send() 사용token 키 값에 푸시 메시지를 보낼 단일 token 값 설정import admin from 'firebase-admin';const token = 'token123456789';const message = { token: token, da.. 2024. 8. 21. [Node.js] PM2로 프로젝트 구동 시 개발/상용 환경 나누기 1. pm2 config 파일 구성// ecopm2.config.jsmodule.exports = { apps: [ { // development name: 'development-name', script: './node_modules/.bin/ts-node', args: './bin/www', // watch: true env: { NODE_ENV: 'development', }, }, { // production name: 'production-name', script: './build/bin/www.js', env: { NODE_ENV: 'production'.. 2024. 7. 18. [Node.js] FCM으로 푸시알림 보내는 API 작성하기 1. serviceAccountKey 발급받기firebase 프로젝트 콘솔 > 프로젝트 설정 > 서비스 계정 > '새 비공개 키 생성' 버튼 클릭다운받은 json파일을 Node.js 프로젝트 내에 넣어준다. 2. FCM 연결하기app.js// app.jsimport fcmConnection from './fcm';fcmConnection(); fcm.js위 1번에서 발급받은 json 파일을 import 해준다.아래 코드에서는 import serviceAccount from '../firebase-admin.json'; 부분이다.// fcm.jsimport * as admin from 'firebase-admin';import serviceAccount from '../firebase-admin.json.. 2024. 7. 10. Nodejs-MongoDB connection error: openssl MongoDB Atlas에서 갑자기 [Alert] You're nearing the maximum connections threshold 라는 제목으로 메일이 왔다.내용을 보아하니 You are receiving this alert email because connections to your cluster(s) have exceeded your threshold, and is nearing the connection limit for the M0 cluster... 라는 내용이다. MongoDB를 연결해서 쓰고 있는 Node.js 프로젝트 로그를 보아하니 아래 메시지가 있었다. 분명 잘 구동되던 것이었는데! mongo connection error! 00216A5BF87F0000:error:0A00043.. 2024. 7. 8. [Cheerio] 현재 태그의 텍스트만 가져오기 크롤링 할 때 Cheerio 패키지를 사용했다. 현재 노드의 텍스트를 뽑아내고 싶은데, text() 함수를 사용했을 때, 하위 노드의 텍스트도 모두 뽑아내는 것을 확인했다. .text()를 쓰면 하위 태그의 텍스트도 다 긁어온다. 예를 들어 만약 태그 안에 태그가 있다면 태그 속에 있는 텍스트도 함께 긁어온다.$('td').text() 하지만 selector로 고른 현재 태그의 텍스트만 뽑아오고 싶다면, 아래처럼 작성하면 된다.$('td').contents().first().text() 2024. 6. 19. [Node.js] nodemon 설치하고 typescript 적용하기 1. nodemon 설치코드를 변경하고 저장했을 때 변경 사항이 바로 적용되도록 하기 위해서 nodemon을 사용한다.개발 시에만 사용할거니까 -save-dev 옵션을 줘서 설치한다.// 패키지 설치npm install -save-dev nodemon 2. typescript 관련 패키지 설치express로 프로젝트를 구동해서 express 관련 패키지도 설치해줬다.npm install --save-dev typescript ts-node @types/node @types/cookie-parser @types/debug@types/express @types/http-errors @types/morgants-node: node.js 프로젝트 구동 시에 ts 파일을 수동으로 컴파일하지 않고 바로 실행시킬 수.. 2024. 6. 12. 이전 1 다음 반응형