2020-03-12

[nodejs] express 사용한 web server 개발 준비


개인적으로 nodejs 공부 하던중에 개인용으로 사용할 간단한 web server를 만들어보면서  블로그 업데이트를 해야겠다고 생각했다.
windows 10에 wsl ubuntu내에서 작업하였다.
nodejs를 공부하던 중이라서 1. 설치 정보의 nodejs, npm, express-generator는 이미 설치 되어 있었다.

1. 사전 설치 정보
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:        18.04
Codename:       bionic

$ nodejs --version
v12.16.1

$ npm --version
6.14.2

$ express --version
4.16.1

2. express 작업 디렉토리 설정
home_server라는 작업 디렉토리를 사용할것이다. 다른 디렉토리를 원하면 아래 명령에서 이름을 바꿔주면 된다.

$ express home_server --view=pug

   create : home_server/
   create : home_server/public/
   create : home_server/public/javascripts/
   create : home_server/public/images/
   create : home_server/public/stylesheets/
   create : home_server/public/stylesheets/style.css
   create : home_server/routes/
   create : home_server/routes/index.js
   create : home_server/routes/users.js
   create : home_server/views/
   create : home_server/views/error.pug
   create : home_server/views/index.pug
   create : home_server/views/layout.pug
   create : home_server/app.js
   create : home_server/package.json
   create : home_server/bin/
   create : home_server/bin/www

   change directory:
     $ cd home_server

   install dependencies:
     $ npm install

   run the app:
     $ DEBUG=home-server:* npm start

3. npm module 설치
express-generator를 사용하여 정상적으로 설정되면 마지막부분에 따라해야할 명령어들이 출력되어 있다. 그대로 실행해주면 된다.

$ cd home_server/
$ npm install
npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.

> core-js@2.6.11 postinstall /mnt/d/workspace/nodejs/home_server/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)

npm notice created a lockfile as package-lock.json. You should commit this file.
added 118 packages from 174 contributors and audited 247 packages in 13.22s

2 packages are looking for funding
  run `npm fund` for details

found 1 low severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details

4. 취약점 수정
3절 설치 과정 마지막에 취약점 정보가 1개 존재한다고한다.
친절하게 npm audit fix를 사용하라고 적혀있다.

$ npm audit fix
npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
+ pug@2.0.4
removed 3 packages and updated 8 packages in 2.373s
fixed 1 of 1 vulnerability in 247 scanned packages

1개의 취약점 중 1개 수정되었다고 출력되었다. 혹시 모르니 다시 한번 입력해보았다.

$ npm audit fix
up to date in 0.532s

2 packages are looking for funding
  run `npm fund` for details

fixed 0 of 0 vulnerabilities in 244 scanned packages

5. test
npm start 명령으로 web server 실행후 웹브라우저로 접속하여보았다.

$ npm start

> home-server@0.0.0 start /nodejs/home_server
> node ./bin/www

5.1) 웹브라우저 접속 결과


5.2) 콘솔 출력 로그
GET / 304 387.352 ms - -
GET /stylesheets/style.css 200 4.508 ms - 111


express를 사용한 웹서버가 정상 동작하는것을 볼수 있다.



2019-02-19

[firefox] 링크 새탭으로 열기


firefox사용시 링크 누르면 현재 탭이 새창으로 변경되는 불편함이 있어서 링크를 새탭으로 여는 설정을 작성한다.

firefox 주소창에 about:config를 입력한다.


browser.search.openintab 의 값을 찾아서 true로 변경한다.

firefox를 재시작한다.

2017-09-15

[FFMPEG] linux mint에서 ffmpeg 빌드 하기


ffmpeg을 직접 빌드해야하는 이슈가 발생하여 linuxmint-18.2-mate-64bit 에서 빌드한 내용을 남긴다.

아래 링크를 참조하여 작업하였다.
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu

1. 종속성 라이브러리 설치
$ sudo apt-get update
$ sudo apt-get -y install autoconf automake build-essential libass-dev libfreetype6-dev libsdl2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev

2. 설치시 사용할 디렉토리 생성
$ mkdir ~/ffmpeg_sources ~/ffmpeg_build ~/bin

3. yasm 설치
$ sudo apt-get install yasm

4. nasm 설치
$ cd ~/ffmpeg_sources
$ wget http://www.nasm.us/pub/nasm/releasebuilds/2.13.01/nasm-2.13.01.tar.bz2
$ tar xjvf nasm-2.13.01.tar.bz2
$ cd nasm-2.13.01
$ ./autogen.sh
$ PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
$ PATH="$HOME/bin:$PATH" make
$ make install

5. libx264 설치
$ sudo apt-get install libx264-dev

6. libx265 설치
$ sudo apt-get install libx265-dev

7. libfdk-aac 설치
$ sudo apt-get install libfdk-aac-dev

8. libfdk-aac 설치
$ sudo apt-get install libmp3lame-dev

9. libfdk-aac 설치
$ sudo apt-get install libopus-dev

10. libfdk-aac 설치
$ sudo apt-get install libvpx-dev

11. ffmpeg 빌드 및 설치
$ cd ~/ffmpeg_sources
$ wget http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
$ tar xjvf ffmpeg-snapshot.tar.bz2
$ cd ffmpeg
$ PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" $ ./configure --prefix="$HOME/ffmpeg_build" --pkg-config-flags="--static" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
$ PATH="$HOME/bin:$PATH" make
$ make install

12. ffmpeg 동작 확인
$ ./ffmpeg -version
ffmpeg version N-87286-g6ce4a63 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
configuration: --prefix=/home/sharpis/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/sharpis/ffmpeg_build/include --extra-ldflags=-L/home/sharpis/ffmpeg_build/lib --bindir=/home/sharpis/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree
libavutil      55. 74.100 / 55. 74.100
libavcodec     57.105.100 / 57.105.100
libavformat    57. 82.100 / 57. 82.100
libavdevice    57.  8.100 / 57.  8.100
libavfilter     6.105.100 /  6.105.100
libswscale      4.  7.103 /  4.  7.103
libswresample   2.  8.100 /  2.  8.100
libpostproc    54.  6.100 / 54.  6.100

13. troubleshoot
A. 11에 configure 에서 "ERROR: x265 not found using pkg-config" 오류 발생 시 libx265을 아래와 같이 소스 설치 후 다시 시도 한다.
$ sudo apt-get install cmake mercurial
$ cd ~/ffmpeg_sources
$ hg clone https://bitbucket.org/multicoreware/x265
$ cd ~/ffmpeg_sources/x265/build/linux
$ PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source
$ make
$ make install


2017-03-04

[MINGW/MSYS] beep음 off 하는 방법


windows에서 msys를 사용하던 중 beep음이 많이 신경이 쓰여서 beep음을 없애야했다.
노가다로 msys 설정 파일들을 확인하면서 찾아낸 방법을 기록해둔다.

msys 창에서 inputrc파일을 연다.
1. inputrc파일 을 연다.
$ vim ~/.inputrc

2. "set bell-style" 이 포함된 라인을 찾아서 다음과 같이 수정한다.
# none, visible or audible
#set bell-style audible
set bell-style none

3. msys 창을 종료 후 다시 실행하면 더이상 beep음이 발생하지 않는다.

4. vimrc 파일을 연다.
$ vim ~/.vimrc

5. 아래 라인을 추가한다.
set noerrorbells
set vb t_vb=

6. vim 을 다시 실행하면 vim beep음도 더 이상 발생하지 않는다.

2015-11-20

[JAVA] JNI용 C header file 생성 (javah)

오랜만에 JNI를 사용하여 라이브러리를 작성할 일이 생겼다.
JNI를 사용할 때 c 함수 형태를 java code에서 호출할 수 있게 생성해야한다.
이를 쉽게 해주는 tool이 javah인데, 너무 오랜만에 사용했더니 사용법잘생각이 안났다.
나중에 다시 찾을때를 위해 간단히 기록해둔다.

javah help 페이지는 아래와 같다.
> javah --help
Usage:
  javah [options] <classes>
where [options] include:
  -o <file>                Output file (only one of -d or -o may be used)
  -d <dir>                 Output directory
  -v  -verbose             Enable verbose output
  -h  --help  -?           Print this message
  -version                 Print version information
  -jni                     Generate JNI-style header file (default)
  -force                   Always write output files
  -classpath <path>        Path from which to load classes
  -cp <path>               Path from which to load classes
  -bootclasspath <path>    Path from which to load bootstrap classes
<classes> are specified with their fully qualified names
(for example, java.lang.Object).

example)
> javah -classpath E:\workspace\android\testpackage\src\main\java>javah -classpath C:\Android\sdk\platforms\android-23\andro
id.jar; testpackage.TestClass

2015-08-30

[debian] apache2 web server 간단한 설정

집에서 사용하는 개인용 Debian에서 apache2로 web server를 설정하는 방법을 기록한다.

1. 준비
Debian 설치시 옵션으로 web server를 사용하겠다고 선택했더니 이미 apache2가 설치되어 있었다. 방화벽도 열려 있었다.
기본 설정 파일 내용은 변경을 거의 안할것다. 일부 보안 관련 설정만 작업 할 것이다.

web root : /var/www/html (기본 설정)

2. security.conf 수정
# vi /etc/apache2/conf-available/security.conf

<Directory />
   AllowOverride None
   Order Deny,Allow
   Deny from all
</Directory>

<Directory /var/www/html>
   AllowOverride None
   Order Deny,Allow
   Allow from all
</Directory>

ServerTokens Prod
ServerSignature Off
TraceEnable On

3. user 추가
# htpasswd -c /etc/apache2/passwd userid

4. 디렉토리 설정
# vi /etc/apache2/conf-available/video.conf
<Directory /var/www/html/video>
   Order Deny,Allow
   AuthType Basic
   AuthName "testauthname"
   AuthUserFile /etc/apache2/passwd
   Require valid-user
</Directory>

5. 설정 파일 link
# ln -s /etc/apache2/conf-available/video.conf /etc/apache2/conf-enabled/video.conf

6. 재시작
# service apache2 restart

웹 브라우저에 video 디렉 토리 접근시 3번 과정에서 추가한 userid와 password를 요구한다.



2015-08-22

[debian] torrent 설정

debian linux에서 torrent daemon(transmission-daemon) 을 설정한다.

1. 준비
torrent 자동 추가 디렉토리 : "/mnt/exhdd/seagate_hdd/torrent/input"
torrent 임시 디렉토리 : "/mnt/exhdd/seagate_hdd/torrent/tmp"
torrent 다운로드 디렉토리 : "/mnt/exhdd/seagate_hdd/torrent/down"


2. 설치
# apt-get install transmission-daemon


3. 서비스 종료 (안하면, 설정이 수정안됨)
# service transmission-daemon stop

4. 설정
# vi /etc/transmission-daemon/settings.json
아래 url에서 설정관련 추가 정보를 얻을수 있다.
https://trac.transmissionbt.com/wiki/EditConfigFiles

{
    "alt-speed-down": 50,
    "alt-speed-enabled": false,
    "alt-speed-time-begin": 540,
    "alt-speed-time-day": 127,
    "alt-speed-time-enabled": false,
    "alt-speed-time-end": 1020,
    "alt-speed-up": 50,
    "bind-address-ipv4": "0.0.0.0",
    "bind-address-ipv6": "::",
    "blocklist-enabled": false,
    "blocklist-url": "http://www.example.com/blocklist",
    "cache-size-mb": 4,
    "dht-enabled": true,
    "download-dir": "/mnt/exhdd/seagate_hdd/torrent/down",
    "download-limit": 100,
    "download-limit-enabled": 0,
    "download-queue-enabled": true,
    "download-queue-size": 5,
    "encryption": 1,
    "idle-seeding-limit": 30,
    "idle-seeding-limit-enabled": false,
    "incomplete-dir": "/mnt/exhdd/seagate_hdd/torrent/tmp",
    "incomplete-dir-enabled": true,
    "lpd-enabled": false,
    "max-peers-global": 200,
    "message-level": 1,
    "peer-congestion-algorithm": "",
    "peer-id-ttl-hours": 6,
    "peer-limit-global": 200,
    "peer-limit-per-torrent": 50,
    "peer-port": 51413,
    "peer-port-random-high": 65535,
    "peer-port-random-low": 49152,
    "peer-port-random-on-start": false,
    "peer-socket-tos": "default",
    "pex-enabled": true,
    "port-forwarding-enabled": false,
    "preallocation": 1,
    "prefetch-enabled": 1,
    "queue-stalled-enabled": true,
    "queue-stalled-minutes": 30,
    "ratio-limit": 2,
    "ratio-limit-enabled": false,
    "rename-partial-files": true,
    "rpc-authentication-required": true,
    "rpc-bind-address": "0.0.0.0",
    "rpc-enabled": true,
    "rpc-password": "torrent_password",
    "rpc-port": 9091,
    "rpc-url": "/transmission/",
    "rpc-username": "torrent_id",
    "rpc-whitelist": "192.168.0.2",
    "rpc-whitelist-enabled": true,
    "scrape-paused-torrents-enabled": true,
    "script-torrent-done-enabled": false,
    "script-torrent-done-filename": "",
    "seed-queue-enabled": false,
    "seed-queue-size": 10,
    "speed-limit-down": 100,
    "speed-limit-down-enabled": false,
    "speed-limit-up": 100,
    "speed-limit-up-enabled": false,
    "start-added-torrents": true,
    "trash-original-torrent-files": false,
    "umask": 18,
    "upload-limit": 100,
    "upload-limit-enabled": 0,
    "upload-slots-per-torrent": 14,
    "utp-enabled": true,
    "watch-dir": "/mnt/exhdd/seagate_hdd/torrent/input",
    "watch-dir-enabled": true,
    "trash-original-torrent_files": true
}


5. 재시작
# service transmission-daemon restart


6. web browser로 동작 확인
web browser에서 http://192.168.0.3:9091/transmission/
id : torrent_id
password : torrent_password