You can use our official NodeJS app server type and templates to generate GraphQL and Express application templates baked with best practices.
Use the Node Server type in your Bit to define a new backend service:
import { NodeServer } from '@bitdev/node.node-server'; export default NodeServer.from({ name: 'corporate-service', mainPath: './corporate-service.app-root.js', });
Our official NodeJS server app type uses ESBuild by default and supports HMR for server development.
Create an express server using the NodeJS env generator templates:
bit create express-server user-server
Run the server:
bit run user-server
See an example for a simple Express server.
Create a GraphQL server using the NodeJS env generator template:
bit create graphql-server user-server
Run the server:
bit run user-server
Your new GraphQL server is now listening to the port shown in the output. You can see an example for a simple GraphQL server here.
The API server templates use our official Node Server type by default, and therefore using ESBuild to build your app.
bit build my-app
If using Ripple CI, simply snap and export your components. Build artifacts can be found on the directory the bit build command will output.
├── my-app.cjs
You can now use node to simply run your app:
node /path/to/output/my-app.cjs
You can use the Node Server to build the server into a NodeJS executable file. To enable this options set the binary
to true:
import { NodeServer } from '@bitdev/node.node-server'; export default NodeServer.from({ name: 'corporate-service', mainPath: './corporate-service.app-root.js', binary: true });
Learn about more options in the official Node Server on the NodeOptions docs.
You can deploy backend services using the deploy function provided to the Node Server:
import { NodeServer } from '@bitdev/node.node-server'; export default NodeServer.from({ name: 'corporate-service', mainPath: './corporate-service.app-root.js', deploy: (context: AppDeployContext) { const artifact = context.artifacts.findByName('app-bundle'); const path = artifact.artifactDir; const url = execSync(`deploy ${path}`).toString('utf-8'); return { url }; } });
Use the deploy function to execute commands, use packages and APIs to deploy your backend service.
You can compose backend services into platforms using the Platform component. Head to Platforms to kearn more on composing backend services to platforms.