nodejs

    nodejs ejs render 대신 html 사용하기

    - app.js // 화면 engine을 ejs로 설정 app.set('view engine', 'ejs'); app.engine('html', require('ejs').renderFile); - index.js const express = require('express'); const router = express.Router(); /* GET home page. */ router.get('/', function(req, res, next) { return res.render('index.html'); }); module.exports = router;

    youtube 영상 다운로드

    app.js const request = require('request'); app.post("/getYoutube", (req, res) => { const cookies = "lang=en; _ga=GA1.2.1682187592.1407390651; _dc=1;"; const options = { url : "http://en.savefrom.net/savefrom.php", form: { sf_url: req.body.sf_url, sf_submit: "" }, method: "POST", headers: { "Cache-Control" : "max-age=0", "Connection" : "keep-alive", "Content-Type" : 'application/x-www-form-urlenc..

    body-parser (urlencoded, extended 옵션)

    request.body에 있는 데이터에 접근하기 위해 사용 //application/json 방식의 Content-Type 데이터 bodyParser.json(); //text/xml 방식의 Content-Type 데이터 bodyParser.text(); //application/x-www-form-urlencoded Content-Type 데이터 bodyParser.urlencoded({extended: true}); extended: true /false 차이점 true : qs모듈을 사용하여 쿼리 스트링 값을 해석 false : querystring 모듈을 사용하여 쿼리 스트링 값을 해석 let data = { info: { name: 'andy', age: 33 }, hobby[1]: sport,..

    req.body null 일때

    nodejs에서 Request 로그를 남길 때 보통 req.body 의 데이터를 남기곤 하는데 파일 첨부 형식의 enctype 일 경우 req.body 는 null 이다. # enctype="multipart/form-data" 인 경우 app.post('/save', (req, res) => { console.log(req.body); //null });

    nodejs 기본 메모리 제한

    32비트 = 512MB64비트 = 1GB

    child_process에서 spawn, exec 차이

    spawn : stream 리턴, 비동기 exec : buffer 리턴, 동기 자식 프로세스로부터 큰 바이너리 데이터를 리턴받는 경우라면 spawn을, 간단한 상태 메시지만 받는 것이라면 exec를 쓴다. // Dependencies var fs = require('fs'); var url = require('url'); var http = require('http'); var exec = require('child_process').exec; var spawn = require('child_process').spawn; // App variables var file_url = 'http://upload.wikimedia.org/wikipedia/commons/4/4f/Big%26Small_edit_1...

    node.js를 이용하여 IOS 푸시 보내기

    PUSH란? 서버에서 정보를 클라이언트로 강제 전달하는 서비스. Apple의 APNS(Apple Push Notification Service) Google의 GCM(Google Cloud Messaging) installation $ npm install apns -sAPI /* notification.payload : Push payload (json타입) notification.badge : 뱃지 숫자 번호 notification.sound : Push 알림음 notification.alert : Push 메시지 텍스트 notification.device : Push 받을 대상 notification.encoding : 메시지 인코딩 타입 (기본 : UTF-8) */const apns = requi..