spring-but-js
v1.1.9
Published
Use features of the Spring Framework in NodeJS!
Downloads
5
Maintainers
Readme
Spring but JS
Use annotations and Spring Inversion of Control in NodeJS! Easily set up a REST endpoint like you would in a Spring Boot application.
Not actually affiliated with Spring.
Install
npm install spring-but-js --save
A demonstration
Below is a small project that makes use of SpringButJs, showcasing simple IoC and Web MVC mechanics to set up a web service.
main.js
const SpringButJs = require('spring-but-js');
SpringButJs.scanComponents('components', process.argv);
components/my-service.js
'@Service'
function MyService() {
this.getHello = function() {
return 'Hello from MyService!';
}
}
components/my-controller.js
'@RestController'
'@RequestMapping("/hello")'
function MyController() {
let myService;
'@Autowired'
this.setMyService = function(_myServive) {
myService = _myService;
}
'@RequestMapping("/")'
this.myOtherFunction = function(req, res) {
res.send(myService.getHello());
}
}
GET http://localhost/hello => 200: 'Hello from MyService!'
Documentation
View the GitHub Wiki for more documentation!