Create and initialize your a directory for your Express application.
$ mkdir node-knex-demo
$ cd node-knex-demo
$ npm init| class CircuitBreaker { | |
| constructor(request, options = {}) { | |
| const defaults = { | |
| failureThreshold: 3, | |
| successThreshold: 2, | |
| timeout: 6000 | |
| } | |
| Object.assign(this, defaults, options, { | |
| request, | |
| state: "CLOSED", |
| CREATE TABLE test | |
| ( | |
| id INTEGER, | |
| parent INTEGER | |
| ); | |
| INSERT INTO test (id, parent) VALUES | |
| (1, NULL), | |
| (2, 1), |
| const pg = require('pg') | |
| // create a config to configure both pooling behavior | |
| // and client options | |
| // note: all config is optional and the environment variables | |
| // will be read if the config is not present | |
| var config = { | |
| user: '', // env var: PGUSER | |
| database: '', // env var: PGDATABASE | |
| password: '', // env var: PGPASSWORD |
const express = require('express');
const path = require('path');
const app = express();
// Allow dotfiles - this is required for verification by Lets Encrypt's certbotThis is a basic collection of things I do when setting up a new headless ubuntu machine as a webserver. Following the steps below should give you a reasonable secure server with HTTP/2 support (including ALPN in chrome) and the fast NGINX server. I am happy to add things so leave a comment.
After creating the server (droplet on DigitalOcean) log in with
| # Note (November 2016): | |
| # This config is rather outdated and left here for historical reasons, please refer to prerender.io for the latest setup information | |
| # Serving static html to Googlebot is now considered bad practice as you should be using the escaped fragment crawling protocol | |
| server { | |
| listen 80; | |
| listen [::]:80; | |
| server_name yourserver.com; | |
| root /path/to/your/htdocs; |
| # Enter this command to create a sudoers override/include file: | |
| # sudo visudo -f /etc/sudoers.d/nginx.overrides | |
| # (Make sure you actually have this in your /etc/sudoers - Run `sudo visudo` to check) | |
| # #includedir /etc/sudoers.d | |
| # This file assumes your deployment user is `deploy` | |
| # Nginx Commands | |
| Cmnd_Alias NGINX_RESTART = /usr/sbin/service nginx restart |
| #!/usr/bin/env bash | |
| if [ $EUID -ne 0 ]; then | |
| echo "You must be root: \"sudo ngxdis\"" | |
| exit 1 | |
| fi | |
| # -z str: Returns True if the length of str is equal to zero. | |
| if [ -z "$1" ]; then | |
| echo "Please choose a site." |
There are two main modes to run the Let's Encrypt client (called Certbot):
Webroot is better because it doesn't need to replace Nginx (to bind to port 80).
In the following, we're setting up mydomain.com.
HTML is served from /var/www/mydomain, and challenges are served from /var/www/letsencrypt.