Coder Social home page Coder Social logo

nbb-express's Introduction

Translating from https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/skeleton_website#creating_the_project

It assumes node/npm are installed, as well as the express application generator:

npm install express-generator -g

Creating the project

This command will create a directory named nbb-express using the Pug template library:

express nbb-express --view=pug

The generator will create (and list) the project's files:

	     create : nbb-express\
	     create : nbb-express\public\
	     create : nbb-express\public\javascripts\
	     create : nbb-express\public\images\
	     create : nbb-express\public\stylesheets\
	     create : nbb-express\public\stylesheets\style.css
	     create : nbb-express\routes\
	     create : nbb-express\routes\index.js
	     create : nbb-express\routes\users.js
	     create : nbb-express\views\
	     create : nbb-express\views\error.pug
	     create : nbb-express\views\index.pug
	     create : nbb-express\views\layout.pug
	     create : nbb-express\app.js
	     create : nbb-express\package.json
	     create : nbb-express\bin\
	     create : nbb-express\bin\www
	  
	     change directory:
	       > cd nbb-express
	  
	     install dependencies:
	       > npm install
	  
	     run the app:
	       > SET DEBUG=nbb-express:* & npm start

Since I'm in Powershell my command is a bit different:

`$ENV:DEBUG = "nbb-express:*"; npm start`
	  > [email protected] start
	  > node ./bin/www
	  
	    nbb-express:server Listening on port 3000 +0ms

Then load http://localhost:3000/

Now we will replace app.js with app.cljs:

(ns app
  (:require ["express$default" :as express]
            ["path" :as path]
            ["mongoose$default" :as mongoose]
            ["./routes/index$default" :as indexRouter]
            ["./routes/users$default" :as usersRouter]
            ["./routes/catalog$default" :as catalogRouter]))

(def app (express))
(def port 3000)

(def mongoDB "mongodb://127.0.0.1/my_database")
(.connect mongoose mongoDB
 #js {:useNewUrlParser true, :useUnifiedTopology true})

(def db (.-connection mongoose))
(.on db "error" (.bind js/console.error "MongoDB connection error:"))

(.set app "view engine" "pug")
(.use app (.static express (.join path (.cwd js/process) "public")))

(.use app "/" indexRouter)
(.use app "/users" usersRouter)
(.use app "/catalog" catalogRouter)

(.listen app port
         (fn [] (println "Example app listening on port" port)))

It works, plus you can define new routes without restarting the server, though you can't redefine existing ones. Progress!

nbb-express's People

Contributors

bobbicodes avatar

Stargazers

Avinash Sridhar avatar Jonathan Kovis avatar Babak Karimi Asl avatar stephen avatar Michiel Borkent avatar Brad Svercl 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.