GithubHelp home page GithubHelp logo

earth-x / next-postgres Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jimmylee/next-postgres-sequelize

0.0 1.0 0.0 244 KB

An example application using React/NextJS + Emotion and Sequelize 4/Postgres, then deployed to Zeit using now-cli

License: MIT License

JavaScript 100.00%

next-postgres's Introduction

next-postgres

This is an example of a web application with posts, comments and server side rendering. It is configured to be deployed to Zeit. It is code you can use without attribution, please enjoy.

An older version is deployed here.

Stack

Why is this useful? Why should I care?

  • The UX and UI are garbage, that means everything you do will be better!
  • Client and server are written in JavaScript.
  • This is a production ready codebase you can use to test a concept you have.
  • Server side rendering has been made simple.
  • Maybe you want to get a head start at a hackathon.

Setup: Prerequisites

I use Homebrew to manage dependencies on a new laptop... You're welcome to use something else.

  • Install Postgres: brew install postgres.
  • Install Node 10+: brew install node. (Or update your node)

Setup: Quick newbies guide to Postgres

  • On OSX, to run Postgres in a tab on the default port.
postgres -D /usr/local/var/postgres -p 5432
  • Postgres config is stored in ./config.js.
  • Local database: sampledb.
  • Username and password as test.

First time Postgres instructions.

# Enter Postgres console
psql postgres

# Create a new user for yourself
CREATE ROLE yourname WITH LOGIN PASSWORD 'yourname';

# Allow yourself to create databases
ALTER ROLE yourname CREATEDB;

# Exit Postgres console
\q

# Log in as your new user.
psql postgres -U yourname

# Create a database named: sampledb.
# If you change this, update config.js
CREATE DATABASE sampledb;

# Give your self privileges
GRANT ALL PRIVILEGES ON DATABASE sampledb TO yourname;

# List all of your databases
\list

# Connect to your newly created DB as a test
\connect sampledb

# Exit Postgres console
\q

I also use a GUI called TablePlus if you don't like command line.

Setup: Run locally

In the root directory run these commands:

npm install
npm install -g sequelize-cli
sequelize db:migrate
npm run dev

Visit localhost:8000 in a browser to start development locally. You will need postgres running.

Deploy

Deploying with now-cli is as simple as

now

# after the deploy, alias to your domain, add "alias" to now.json first
now alias

Make sure you configure your alias for zeit.world

Secrets

You can update production secrets in now-secrets.json and now.json. You can add a secret to your Zeit deployment by typing

now secrets add database-username admin

Questions?

Feel free to slang any feels to @wwwjim.

next-postgres's People

Contributors

jimmylee avatar pruhstal avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.