Instantly share code, notes, and snippets.

View server.js
...
// set routes
app.use(require("./app/routes"));
...
View home.ejs
<div class="jumbotron">
<h1 class="display-3">Jumbo heading</h1>
<p class="lead">Jumbo helper text</p>
<hr class="my-2">
<p>More info</p>
<p class="lead">
<a class="btn btn-primary btn-lg" href="Jumbo action link" role="button">Jumbo action name</a>
</p>
</div>
View routes.js
var express = require("express");
router = express.Router();
mainController = require("./controllers/main.controller");
// export router
module.exports = router;
// set router home
router.get("/" , mainController.showHome)
View main.controller.js
module.exports = {
showHome,
}
function showHome(req,res){
res.render("home");
}
View server.js
// import express
const express = require('express')
app = express()
port = process.env.port || 3000
expressLayout = require('express-ejs-layouts');
// configure application
// tell application express to get static ass css
app.use(express.static(__dirname + '/public'));
View layout.ejs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Auth</title>
<!-- css -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/style.css">
View server.js
// import express
const express = require('express')
app = express()
port = process.env.port || 3000
// configure application
// set routes
app.get("/" , (req,res) => {
res.send("hello")
View Terminal
npm init
yarn add express ejs express-ejs-layouts
View package.json
{
...
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "node server.js"
},
...
}