-2

I have cloned the Cloud-express Repo from: https://github.com/AGEDB-INC/Cloud-Express

and after cloning, I run the command npm install to install the required modules.

and then I run npm run start it runs the Frontend.

But when I run the Backend in the backend folder using node index.js

It gives this error:

RangeError: express-jwt: `secret` is a required option
    at expressjwt (/home/kamleshk/age_installation/AGECLOUD/backend/node_modules/express-jwt/dist/index.js:54:15)

enter image description here

Sam Mason
  • 15,216
  • 1
  • 41
  • 60
Kamlesh Kumar
  • 351
  • 1
  • 7
  • Please review *[Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/)* (e.g., *"Images should only be used to illustrate problems that* ***can't be made clear in any other way,*** *such as to provide screenshots of a user interface."*) and [do the right thing](https://stackoverflow.com/posts/76907158/edit). Thanks in advance. – Peter Mortensen Sep 02 '23 at 13:44

8 Answers8

1

You need to set valid KEY for express-jwt. Create a .env file & add the follwoing as per README:

The README file says:

-Create a `.env` file in the `backend` directory and add the following fields in it: 
```
PORT = 4000
SECRET_KEY = ApacheAgeViewer
MONGO_URI = mongodb+srv://safi50:cloudExpress@cloud-express.le2yrog.mongodb.net/cloud-express-users?retryWrites=true&w=majority
```
- Secret Key is used to encrypt JWT Token
- MONGO_URI contains the string to connect to our online Database cluster. It will be replaced with an official production string once development is complete.

This key is being used in index.js in backend folder at line:53. Also, make sure that it is referring to correct value (Im sure it is).

app.use(
  expressjwt({
    secret: process.env.SECRET_KEY,
    algorithms: ['HS256'],
    getToken: (req) => req.cookies.token,
  }).unless({ path: ['/user/login', '/user/signup', '/user/googleSignin'] })
  );

After this follow the same steps to execute the code & you are good to go.

npm run start

and

cd backend
node index
Huzaifa
  • 484
  • 4
  • 8
0

It seems you did not create the .env at the backend so that the configuration are not correctly set as it is described on the documentation there https://github.com/AGEDB-INC/Cloud-Express/tree/main/backend

Steps:

  1. Create a .env File and configure it as mentioned in the backend README file
  2. Run the MongoDB server in a new terminal

Than npm start as you have mentioned

0

Try installing the required node modules using the following command:

npm run setup

And then

npm run start

Follow the instructions in the repository. Remember to create the .env file and add the required fields.

Wendel
  • 763
  • 1
  • 12
0

in the root folder run

npm run setup

to install required modules in the whole project.

and as far as the error is concerned,

you need to create a .env file in the backend folder

then copy this block and paste in .env file

then in the backend folder run the following command

node ./index.js

0

according to Readme BACKEND instructions, you need to create the .ENV file in the backend directory and add the following fields in it:

PORT = 4000
SECRET_KEY = ApacheAgeViewer
MONGO_URI = mongodb+srv://safi50:cloudExpress@cloud-express.le2yrog.mongodb.net/cloud-express-users?retryWrites=true&w=majority
- Secret Key is used to encrypt JWT Token
- MONGO_URI contains the string to connect to our online Database cluster. It will be replaced with an official production string once development is complete.

after this you have to run the MongoDB server in a new terminal:

cd backend
npm install      
node index    
Marcos Silva
  • 115
  • 5
0

Go to main folder , run npm run setup to prepare all project parts.
Make a .env file in "backend" section, paste settings, run node ./index.js.
Use node ./index.js in "backend" to start the project's engine.

Zeeshan
  • 3
  • 1
0

Maybe there is an issue that you didn't create .env at the backend so that's why configurations are not set correctly. You can follow the mentioned steps to resolve your issue.

1- Create a .env File and configure it as mentioned in the backend README file 2- Run the MongoDB server in a new terminal

After these two steps, you can do "npm" start as you mentioned

0

Use the

npm run setup

to get done with the installations and create an env file in the backend directory and follow the instructions in the readme file. Afterwards you can run the MongoDB server.

Now you can npm run start