Code Monkey home page Code Monkey logo

lizchang's Introduction

lizchang

This is a simple Node.js / MongoDB app that powers my wife's design portfolio. There are different ways to set this up. You could run it off of the data.json file directly using the FS Module, or you could set it up to use MongoDB. I've done the latter, so I will run through the basics of how to do that here.

Server Setup

Basics

The site runs on two Digital Ocean Linux droplets. The first server is for the application itself, and the second is for the Mongo database. Detailed setup for Ubuntu servers at Digital Ocean is covered on their site, but the general idea is:

  • Add two droplets and add a new ssh key in control panel
  • Create new root password for your servers
  • Copy the ssh public key to your servers with the following command:
cat ~/.ssh/id_rsa.pub | ssh root@YOUR_SERVER_IP "cat >> ~/.ssh/authorized_keys"
  • Create new users for your application and database servers
  • You may need to add the ssh key to your new user:
cat ~/.ssh/id_rsa.pub | ssh YOUR_USER@YOUR_SERVER_IP "mkdir -p ~/.ssh && cat >>  ~/.ssh/authorized_keys"

Log in and Configure MongoDB

At this point you should be able to log into your database server:

ssh YOUR_USER@YOUR_SERVER_IP

Open the mongo config:

nano /etc/mongod.conf

Change the bind ip to allow for external connections:

bind_ip = 0.0.0.0

Assuming you have the mongodb client installed, create a general database collection for the site:

mongoimport --host YOUR_SERVER_IP --port 27017 --db YOUR_DB_NAME --collection site --drop --file data-mongo-site.json

Create another database collection for the design projects:

mongoimport --host YOUR_SERVER_IP --port 27017 --db YOUR_DB_NAME --collection projects --drop --file data-mongo-projects.json

Test your database by trying to connect remotely:

mongo --host YOUR_SERVER_IP
> use YOUR_DB_NAME
switched to db YOUR_DB_NAME
> db.projects.find()

Adding a Firewall

For security purposes you should do a few things to lock down your database server. The bare minimum would be to set up a firewall and limit connections:

sudo apt-get install ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw allow from ip.address.to.allow
sudo ufw enable

App Setup

The app itself is a simple Node.js app using Express. There are just a few things worth pointing out.

Configuration

The app configuration is handled by an NPM module called nconf. Nconf allows for hierarchical configuration merges. So in this case there is a config on the server and a default config for running locally, which you can see in nconf_setup.js.

Templating

Hogan is used as the templating engine.

Data Access

Since this is not a high traffic website data access is very straightforward. The mongodb client is used to connect to the external database server and query the data. When the data is returned, it is rendered.

Process Management

pm2 is used to manage server processes for the application as outlined here.

Build

There is a simple build process in place for the app using Webpack. js/nav.js as well as all css files are bundled in js/main.js and the output is pushed to public/dist. Assuming you have webpack installed, to create a production build simply run the following command from the root:

webpack -p

lizchang's People

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.