geraldokandonga / votenamibia-api

Find Voting Information, Region, Constituencies and Polling Stations for Namibia's Regional, Local and Presidential Elections.
http://www.vote.com.na
MIT License
0 stars 3 forks source link

Cannot read property 'replace' of undefined #1

Closed mtshikomba closed 3 years ago

mtshikomba commented 3 years ago

Not sure what is causing the error below but whenever I do $ npm run dev OR $ npm run start it pops up and I can't do anything else. I am using Ubuntu 16.04.

(base) tangos@ubuntu:~/votenamibia$ npm run dev

vote@1.0.0 dev nodemon server.js

[nodemon] 2.0.6 [nodemon] to restart at any time, enter rs [nodemon] watching path(s): . [nodemon] watching extensions: js,mjs,json [nodemon] starting node server.js UNCAUGHT EXCEPTION! Shutting down... TypeError Cannot read property 'replace' of undefined [nodemon] app crashed - waiting for file changes before starting...

Here is my npm and node version not sure if it has anything to do with this but i had to upgrade from an earlier:

(base) tangos@ubuntu:~/votenamibia$ npm -v 7.0.14 (base) tangos@ubuntu:~/votenamibia$ node -v v15.3.0

geraldokandonga commented 3 years ago

Hi @dev-mtshikomba have you run npm install ?

Also you need to have MongoDB Compass Community installed locally on your machine and create a database with the name votenamibia, or you can still connect to mongoDB through your account if you have

To connect MongoDB remote bellow is the code DATABASE=mongodb+srv://<yourusername>:<PASSWORD>@cluster0-bev59.mongodb.net/votenamibia ?retryWrites=true&w=majority DATABASE_PASSWORD=<PASSWORD>

To Connect locally DATABASE_LOCAL=mongodb://localhost:27017/votenamibia

That's all

geraldokandonga commented 3 years ago

Create a config.env file and add the following

`APP_NAME=VoteNamibia NODE_ENV=development PORT=3000

DATABASE_PASSWORD= DATABASE_LOCAL=mongodb://localhost:27017/

JWT_SECRET=never- JWT_EXPIRES_IN=90d JWT_COOKIE_EXPIRES_IN=90

EMAIL_USERNAME=mailtrapusername EMAIL_PASSWORD=mailtrappassword EMAIL_HOST=smtp.mailtrap.io EMAIL_PORT=25`

You need the above config.env in order to run it locally

mtshikomba commented 3 years ago

I've run npm install, I should create the config.env file in the root directory right? See Image below...

Screenshot from 2020-11-26 21-43-21

mtshikomba commented 3 years ago

I installed MongoDB locally in a docker image running at port 8081. See Image below.

Screenshot from 2020-11-26 21-47-09

geraldokandonga commented 3 years ago

Thats mongodb connection error, but can you connect to it with other apps that you may have worked on, if you are already connected to it through another app than I think you have to use the same method

And again don't forget to setup your mailing configuration, you need to do sign in if you want to add some testing data to the database

But the setup seems to be fine, thats all you need to run it locally

geraldokandonga commented 3 years ago

Also you need to expose your port to mongo by running mongo --port 8081 in your terminal

mtshikomba commented 3 years ago

Perfect this worked. I've added a Docker Image for MongoDB and Mongo Express to the project. I'll submit a pull request shortly.

Screenshot from 2020-11-26 21-43-21

mtshikomba commented 3 years ago

But I used the default port instead, just for consistency.

geraldokandonga commented 3 years ago

Great is it working now?