express에서 node-cron schedule 만들기
1. app.js 에서 하단에 입력
2. 최상단에 schedule 폴더 생성 및 scheduleJob.js 파일 생성
3. scheduleJob.js 파일내용
cron.schedule('* * * * *', () => {
1분에 한번씩 진행 하라는 부분임.
2018.11.05
2018.10.30
2018.10.23
2018.10.23
2018.10.23
2018.10.10
2018.08.23
2016.12.13
1. app.js 에서 하단에 입력
2. 최상단에 schedule 폴더 생성 및 scheduleJob.js 파일 생성
3. scheduleJob.js 파일내용
cron.schedule('* * * * *', () => {
1분에 한번씩 진행 하라는 부분임.
가상 도메인으로 nodejs 설정 방법
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /home/user/node소스 폴더
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</Location>
</VirtualHost>
파일로 생성해서 사용중
app.js 위치에 util 폴더 생성 후 sendmail.js파일 생성
필요한 곳에서 선언
콜백이 필요하면 응용해서 사용해 보시길....
express mariaDB 및 mysql 접속 정보
multipleStatements 사용시 다중 쿼리를 세미콜론으로 분리해서 처리 할 수 있다.
예)
var sql = `select * from table;`;
sql += `select * from table2;';
connection.query(sql, callback);
connection.release();
callback함수에서 받을시에는 Array로 받아짐.
test( function(err, row) {
console.log(JSON.stringify(row))
row[0] --> 첫번째 쿼리 실행 데이터
row[1] --> 두번째 쿼리 실행 데이터
});
물론 CURD 모두 가능함.
1. pm2 설치(ubuntu, Mac)
sudo npm install pm2@latest -g
2. app.js 파일 위치에 myapp.config.js 파일 생성
name : 프로세스목록에서 보여질 이름을 지정한다. (도메인으로 하면 좋을듯...)
3. 실행하기
pm2 start myapp.config.js
아래 로그 출력 됨.
[PM2] Spawning PM2 daemon with pm2_home=/home/ubuntu/.pm2
[PM2] PM2 Successfully daemonized
[PM2][WARN] Applications http://www.domain.co.kr not running, starting...
[PM2] App [http://www.domain.co.kr] launched (1 instances)
┌─────────────────────────────┬────┬─────────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬────────┬──────────┐
│ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├─────────────────────────────┼────┼─────────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼────────┼──────────┤
│ http://www.domain.co.kr │ 0 │ 0.0.0 │ fork │ 12614 │ online │ 0 │ 0s │ 0% │ 23.2 MB │ ubuntu │ disabled │
└─────────────────────────────┴────┴─────────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
4. 중지하기
$ pm2 stop. myapp.config.js
[PM2] [http://www.domain.co.kr](0) ✓
┌─────────────────────────────┬────┬─────────┬──────┬─────┬─────────┬─────────┬────────┬─────┬────────┬────────┬──────────┐
│ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├─────────────────────────────┼────┼─────────┼──────┼─────┼─────────┼─────────┼────────┼─────┼────────┼────────┼──────────┤
│ http://www.domain.co.kr. │ 0 │ 0.0.0 │ fork │ 0 │ stopped │ 0 │ 0 │ 0% │ 0 B │ ubuntu │ disabled │
└─────────────────────────────┴────┴─────────┴──────┴─────┴─────────┴─────────┴────────┴─────┴────────┴────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
5. 재시작 하기
$ pm2 restart. myapp.config.js
[PM2] Applying action restartProcessId on app [http://www.domain.co.kr](ids: 0)
[PM2] [http://www.domain.co.kr](0) ✓
┌─────────────────────────────┬────┬─────────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬────────┬──────────┐
│ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├─────────────────────────────┼────┼─────────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼────────┼──────────┤
│ http://www.domain.co.kr. │ 0 │ 0.0.0 │ fork │ 12693 │ online │ 1 │ 0s │ 0% │ 17.7 MB │ ubuntu │ disabled │
└─────────────────────────────┴────┴─────────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
터미널을 종료해도 운영은 계속....
배열 처리시 첫번째 값에 대한 검증만 처리 되므로 확장 부분을 추가하면 나머지 기능도 처리 함.
<input type="text" name="test[]">
<input type="text" name="test[]">
<input type="text" name="test[]">
<input type="text" name="test[]">
node.js (express) 에서 request 받을시에는 req.body['test[]']로 받으면 배열로 받아짐.
express를 이용한 첨부파일 암호화 및 S3 업로드
1. router POST 업로드 호출 후
awsFileUpload.js 파일
crypto.js
awsconfig.json S3 키발급