spring-but-js

1.1.9 • Public • Published

Spring but JS

NPM

Build Status

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!

Package Sidebar

Install

npm i spring-but-js

Weekly Downloads

10

Version

1.1.9

License

WTFPL

Unpacked Size

45.6 kB

Total Files

25

Last publish

Collaborators

  • evertverschoor