While using @cubejs-backend/server-core i am able to start the app but app is not running

const { CubejsServerCore } = require('@cubejs-backend/server-core');
const express = require('express');
const path = require('path');
const expressApp = express();
const dbType = 'mysql';
const options = {
    dbType,
    logger: (msg, params) => {
        console.log(`${msg}: ${JSON.stringify(params)}`);
    },
    schemaPath: path.join('assets', 'schema')
};
require('dotenv').config();
CubejsServerCore.create(options).initApp(expressApp);

The above one is my index.js file.

I have also started the app. but when i launch the same in browser i am getting Server cant be reached message

Could anyone help? where it is going wrong?

i think you missing server listen you just create express app not listen

@rongfengliang , inspite of giving that also im facing same issue

can you share your code ?

thanks for the awesome information.

@rongfengliang I got it by using expressApp.set

Thanks

after

CubejsServerCore.create(options).initApp(expressApp);

add

expressApp.listen(4000)

@Ishwarya_Rajan better way is use @cubejs-backend/server not server-core

1 Like

Hey @Ishwarya_Rajan! Thank you for the question!

First, I would definitely recommend to migrate your Cube.js app from the index.js file to cube.js file. Please review this migration guide: https://cube.dev/docs/configuration/overview#migrating-from-express-to-docker.
You can transfer the database credentials (like dbType) to the .env file. Please read the docs about connecting to the database: https://cube.dev/docs/connecting-to-the-database

To save the behavior of your logger you should add it to the cube.js file:

module.exports = {
  logger: (msg, params) => {
    console.log(`${msg}: ${JSON.stringify(params)}`);
  },
};

Then, run Cube.js with Docker: https://cube.dev/docs/getting-started/docker

1 Like