Skip to content

node-se2.md

node request

bash
npm i --s request
js
const options = {
    uri:'http://localhost:10021/rest', 
    method: 'GET',
    qs: {
        priority:'high',
    },
}
request(options, function (err, httpResponse, body) {
    //callback
    console.log('success')
    // console.dir(httpResponse)
    // console.dir(body)
    res.status(200).send('/file/downloadImg?sFileURL=1667983894625.png')

})

  
const options = {
    uri:'http://localhost:10021/api/image/upload', 
    method: 'POST',
}
request.post(options, function (err, httpResponse, body) {
    //callback
    console.log('success')
})

json to img tag

js
    function flatten(data) {
        var result = {};
        function recurse(cur, prop) {
            if (Object(cur) !== cur) {
                result[prop] = cur;
            } else if (Array.isArray(cur)) {
                for (var i = 0, l = cur.length; i < l; i++)
                    recurse(cur[i], prop ? prop + "." + i : "" + i);
                if (l == 0)
                    result[prop] = [];
            } else {
                var isEmpty = true;
                for (var p in cur) {
                    isEmpty = false;
                    recurse(cur[p], prop ? prop + "." + p : p);
                }
                if (isEmpty)
                    result[prop] = {};
            }
        }
        recurse(data, "");
        return result;
    }

    function replacer(key, value) {
        // console.log(typeof value)
        // console.log('key -> ' + key + "| value ->" + value);
        // console.log(key +"='" + value + "'")
        if (typeof value === "string") {
            jsonToTagString += key + "='" + value + "' "
            return undefined;
        }
        if (typeof value === "number") {
            jsonToTagString += key + "=" + value + " "
            return 1;
        }
        return value;
    }
    var jsonToTagString = ''
    var imgTags = {
        width: 600,
        // height: 400,
        hint: 'hint'
    }
    JSON.stringify(imgTags, replacer, ' ')
    console.log(jsonToTagString)

    var tagString = JSON.stringify(this.imgTags);
    var tempSplit = tagString.replace("{", "").replace("}","").split(',');
    var result = ""
    for (var index = 0; index < tempSplit.length; index++){
        var tagSplit = tempSplit[index].split(':');
        result += tagSplit[0].replaceAll("\"", "") + "=" + tagSplit[1].replaceAll("\"", "\'") + " "
    }
    console.log(result)

references

node.md

proxy setting

bash
npm config set proxy http://192.0.0.4:10001
npm config set https-proxy http://192.0.0.4:10001
npm config set strict-ssl false
npm config set registry http://registry.npmjs.org/

# confirm: ~/.npmrc
npm config list

nvm

bash
nvm list
nvm install 12.22.9
nvm alias default 12.22.9

추가로 할것

노드 설치후 확인

bash
# 노드 확인
node -v

# npm 확인
npm -v

node를 입력하고 직접 작성해도 됨

  1. npm init -y를 실행 시 package.json 파일 생성
  2. npm install을 하면 package.json에 있는 모듈을 설치함

unable to verify the first certificate

bash
npm config set registry http://registry.npmjs.org/ --global

해당 프로젝트에서만 사용하는 모듈 모카설치 (Fromt-End 단위 테스트 프레임워크)

  1. npm install mocha --save-dev
  2. npm install mocha -g 전역(C:\Users\사용자명\AppData\Roaming\npm)으로 사용
  3. npm link mocha 전역으로 설치한 모듈을 심볼릭링크로 사용
bash
npm list
npm list -g
npm ls
npm ls -depth=0

http://webframeworks.kr/tutorials/nodejs/api-server-by-nodejs-01/

1. 다운로드

https://nodejs.org/en/download/

2. 설치

bash
mkdir codlab-nodejs
cd codlab-nodejs
npm init

3. app.js

js
const http = require('http');

const hostname = '127.0.0.1';const port = 3000;

const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');});

server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);});

4. node app.js

5. npm start

6. curl -X GET '127.0.0.1:3000'

port number ended with

7. mysql

# 에러발생시
Client does not support authentication protocol requested by server; consider upgrading MySQL client
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '비밀번호'

8. 스트리밍

9. 채팅

10. Node.js 얼굴인식

bash
git clone https://turtle.scm.azurewebsites.net:443/turtle.git

11. 배포

12. Angularjs

angular + nodejs-express

13. Azure에 Angular 배포

bash
npm install
npm install -g @angular/cli
ng install kuduscript -g

ng build -prod

ng update @angular/cli @angular/core

14. Angular 관련

15. Angular-Cli를 Azure에 배포 (20191004금)

bash
npm install -g @angular/cli
ng new hello-world --defaults
cd hello-world
ng add @azure/ng-deploy

git push https://turtle.scm.azurewebsites.net:443/turtle.git HEAD:master --tags -f

Invalid Host header

ng serve를 실행했을 떄 포트로는 접근이 가능하지만 url로 접근 시 에러가 발생함

서버실행시 --disableHostCheck

bash
cd C:\inetpub\wwwroot\node
ng serve --host 0.0.0.0 --port 4200 --disableHostCheck
pause

https://tbang.tistory.com/124

webpack.config.js:

js
var config = {
    // ...
    devServer: {
        contentBase: path.resolve(__dirname, './src'),
        disableHostCheck: true,
        host: "0.0.0.0" // default : 127.0.0.1
    }
    // ...
};

module.exports = config;

C:\inetpub\wwwroot\node\node_modules\@angular-devkit\build-angular\src\utils

Running Batch Script on remote Server via PowerShell

17. Angular 모듈 추가

bash
ng g c menu4 --module home
ng g c

18. mongodb

js
db.collection.insert({test:'newValue'})
db.collection.find()

19. Angular 기본사이트 만들기

20. JSON 관련오류 크롬에서 적용 안됨

--disable-web-security --user-data-dir

Oracle 11g Express 다운로드 oracle.com/database/technologies/oracle-database-software-downloads.html

21. Bootstrap