Express
We use express to start a web server and to control it. We also use body parsing, cookie parsing and helmet to keep the server secure and functional so you don't have to.
You can access the express server through the module (1) or on startup in the constructor (2)
1
// 1
2
const app = require("js-spring").app;
3
4
// 2
5
const SpringJS = require("js-spring");
6
const { app } new SpringJS({ name: "test" });
Copied!
We recommend for multiple files by starting up in a main file and accessing the express app using the first method

Example usage

1
const SpringJS = require("js-spring");
2
const { app } new SpringJS({ name: "test" });
3
4
app.use(function(req, res, next) {
5
req.session.name = "DanCodes";
6
console.log("Middleware rocks! just like Spring.js");
7
next();
8
});
9
10
app.get("/", function(req, res) {
11
res.status(200).send("I'm awake!");
12
});
13
14
app.post("/body", function(req, res) {
15
res.status(200).send(req.body);
16
});
17
18
app.get("/session", function(req, res) {
19
res.status(200).send(req.session.name)
20
});
Copied!
Last modified 2yr ago
Copy link