Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Hopefully this helps you pull together the millions of pieces and things needed to put together a basic express app without the generator.
===========INSTRUCTIONS FOR EXPRESS APP================
npm init
-> Blank
-> Blank
-> Fill out Description
-> type app.js for entry point
-> Blank
-> Blank
-> License MIT
-> Enter for OK
Just created a package.json
npm install --save express pg knex body-parser hbs
Bunch of stuff installs
You just installed Express, Postgresql, knex, body-parser, and handlebars
in the main directory
touch app.js .gitignore .env
create the following directories
with the following commands
mkdir bin
mkdir db
mkdir public
mkdir routes
mkdir views
in db create knex.js
in views create all.hbs error.hbs index.hbs layout.hbs new.hbs
in routes create index.js users.js
in public mkdir images javascripts stylesheets
knex init
This will create a knexfile.js for your database configuration.
Change your entire knexfile.js to read
module.exports = {
development: {
client: 'postgresql',
connection: 'postgres://localhost/DATABASE_NAME',
production: {
client: 'postgresql',
connection: process.env.DATABASE_URL
change DATABASE_NAME to whatever you named your database
Change your app.js file to read the following:
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('it worked');
app.listen(3000, function () {
console.log('This shit is working yo');
You will ultimately need to add more configuration and middleware in this file but this is enough to start you out.
now we'll create the database
createdb testdatabase
knex migrate:make testdatabase
Just created a migrations folder with a migrations file in the folder
Now make seed folder by running
seeds folder was just made with data
Your express app should be up and running to use commands
in the terminal
point your browser to http://localhost:3000/
it worked should show up in your browser Now
There is WAYYYYYY more configuration and setup to get done but at least you'll get to see it working in its most basic form.
At this point you still have 1,000 more steps.****DISCLAIMER I almost make no claim that this is the best or even a
good way to do it. I just put this together as a way to practice.
For further practice it might help to create a folder called expresspractice
then within that folder do mkdir practice1 practice2 practice3 practice4 practice5
That will make 5 folders where you can build and burn 5 times to pickup the pace in setting it up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment