- Node.js 12+ and npm 6+
- MongoDB 5.0+
mkdir my-beamjs-app
cd my-beamjs-app
npm init -ynpm install beamjs functional-chain-behaviour mongoose-timestamp{
"name": "my-beamjs-app",
"version": "1.0.0",
"main": "server.js",
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js"
},
"dependencies": {
"beamjs": "latest",
"functional-chain-behaviour": "latest",
"mongoose-timestamp": "latest"
},
"devDependencies": {
"nodemon": "^3.0.1"
},
"engines": {
"node": ">=18.0.0",
"npm": ">=9.0.0"
}
}// server.js
'use strict';
var beam = require('beamjs');
beam.database('main', {
type: 'mongodb',
name: 'myapp'
}).app(__dirname + '/behaviours', {
path: '/api/v1',
parser: 'json',
port: 8282,
origins: '*'
});mkdir -p behaviours/app/health// behaviours/app/health/index.js
'use strict';
var backend = require('beamjs').backend();
var behaviour = backend.behaviour();
var { FunctionalChainBehaviour } = require('functional-chain-behaviour')();
module.exports.health = behaviour({
name: 'health',
inherits: FunctionalChainBehaviour,
version: '1',
type: 'database',
path: '/health',
method: 'GET',
parameters: {},
returns: {
status: { key: 'status', type: 'body' }
}
}, function (init) {
return function () {
var self = init.apply(this, arguments).self();
self.catch(function (e) {
return null;
}).next().map(function (response) {
response.status = 'healthy';
}).end();
};
});// behaviours/index.js
'use strict';
require('./app/health');npm startTest: curl http://localhost:8282/api/v1/health
# .env
DATABASE_NAME=myapp
PORT=8282
NODE_ENV=developmentmy-beamjs-app/
├── server.js
├── package.json
├── behaviours/
│ ├── index.js
│ ├── app/
│ │ └── health/
│ │ └── index.js
│ ├── user/
│ ├── internals/
│ ├── policies/
│ └── jobs/
├── models/
└── services/
You're ready to build with BeamJS! 🚀
Continue reading the documentation: