Examples

Advanced example

1
const SpringJS = require("js-spring");
2
const { app, database } = new SpringJS({
3
name: "advanced",
4
port: 8080,
5
log: true,
6
mongo: "mongodb://localhost:27017/",
7
viewsDir: "./views",
8
publicDir: "./public"
9
});
10
11
app.get("/", function(req, res) {
12
database.set("Startup", new Date());
13
res.send("You visited at " + database.get("Startup"));
14
});
Copied!

EJS

1
const SpringJS = require("js-spring");
2
const { app, database } = new SpringJS({
3
name: "advanced",
4
port: 8080,
5
log: true,
6
mongo: "mongodb://localhost:27017/",
7
viewsDir: "./views",
8
publicDir: "./public"
9
});
10
11
app.set("view engine", "ejs");
12
13
app.get("/", function(req, res) {
14
res.render("index", { time: new Date() });
15
});
Copied!

Session

1
const SpringJS = require("js-spring");
2
const { app, database } = new SpringJS({
3
name: "advanced",
4
port: 8080,
5
log: true,
6
mongo: "mongodb://localhost:27017/",
7
viewsDir: "./views",
8
publicDir: "./public"
9
});
10
11
app.set("view engine", "ejs");
12
app.use(function(req, res, next) {
13
req.session.username = "Tester";
14
next();
15
});
16
17
app.get("/", function(req, res) {
18
res.render("index", { name: req.session.username });
19
});
Copied!
Last modified 2yr ago