Last active
May 10, 2017 08:56
-
-
Save a-x-/f71fc500588ff7868a5012dc9e2cf8ab to your computer and use it in GitHub Desktop.
obsolete express app boilerplate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # RUN latest version: | |
| # wget https://github.yandex-team.ru/gist/invntrm/8e42ab1cd74966541a65/raw/express.js.init.sh && chmod a+x express.js.init.sh && ./express.js.init.sh && rm express.js.init.sh | |
| # **NOT** USE: wget -qO- https://github.yandex-team.ru/gist/invntrm/8e42ab1cd74966541a65/raw/express.js.init.sh | sh | |
| git init | |
| # | |
| # install some npm modules | |
| npm init -y | |
| npm install --save express | |
| tee index.js <<'INDEXJS' | |
| var express = require('express'); | |
| var app = express(); | |
| var Promise = this.Promise || require('promise'); | |
| var request = require('superagent-promise')(require('superagent'), Promise); | |
| var _ = require('lodash'); | |
| var swig = require('swig'); | |
| var path = require('path'); | |
| var process = function(req, res) { | |
| res.end('im working!..'); | |
| }; | |
| app.get('/pr/:task/badge.svg', process); | |
| var server = app.listen(30007, function () { | |
| var host = server.address().address; | |
| var port = server.address().port; | |
| console.log('Example app listening at http://%s:%s', host, port); | |
| }); | |
| INDEXJS | |
| echo node_modules > .gitignore | |
| # | |
| # install deps | |
| type ned >/dev/null 2>&1 || npm install -g ned | |
| npm install --save $(ag require | grep -oE "require\(\s*'(\w|-|_|\.)+'\s*\)" | ned -S "require\(\s*'|'\s*\)" '' | grep -vE 'child_process|fs') | |
| # | |
| # install and setup gulp | |
| npm install --save-dev gulp-develop-server gulp | |
| tee gulpfile.js <<'GULPFILEJS' | |
| var paths = { | |
| scripts: ['index.js', '*.js'] | |
| }; | |
| var gulp = require('gulp'), | |
| server = require('gulp-develop-server'); | |
| // run server | |
| gulp.task( 'server:start', function() { | |
| server.listen( { path: paths.scripts[0], serverFiles: paths } ); | |
| }); | |
| // restart server if app.js changed | |
| gulp.task( 'server:restart', function() { | |
| gulp.watch( paths.scripts, server.restart ); | |
| }); | |
| gulp.task('default', ['server:start', 'server:restart']); | |
| GULPFILEJS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment