NodeJS Mongoose can connect from one linux directory but not another - node.js

Several months ago, I set up a production NodeJS app that uses mongoose to connect to a MongoDB database with the following connection string:
mongodb://#127.0.0.1:27017/invoice_app?retryWrites=true&w=majority
I did not need to supply a username or password and everything worked.
I wanted to make a copy of the NodeJS project on the same server and point it to the same database. I'll call this the staging NodeJS project. However, everytime I try to npm start my staging project, I get the error (node:11495) UnhandledPromiseRejectionWarning: MongoParseError: No username provided in authority section.
As far as I can tell, this staging project is the exact same as the production one. Line by line, they should be the same, except they are in different directories. I reused the exact same connection string. The NodeJS project is used owned/executed by the same user.
Why can mongoose connect from one directory but not another? Is there something else I completely misunderstood?

The issue was that I had deleted the node_modules directory from my staging project along the way. And when I ran the npm install in the staging directory, it didn't actually give me the correct node_modules package versions as production. Here was the relevant lines from package-lock.json that resolved my issues in staging:
"mongodb": {
"version": "3.3.5",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.3.5.tgz",
"integrity": "sha1-ONUxATr+3pKw3SguO588CMm9/zs=",
"requires": {
"bson": "^1.1.1",
"require_optional": "^1.0.1",
"safe-buffer": "^5.1.2",
"saslprep": "^1.0.0"
}
},
"mongoose": {
"version": "5.7.13",
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.7.13.tgz",
"integrity": "sha1-2Ou8Fc+xnQFM8fvUt69BPXWVLUY=",
"requires": {
"bson": "~1.1.1",
"kareem": "2.3.1",
"mongodb": "3.3.5",
"mongoose-legacy-pluralize": "1.0.2",
"mpath": "0.6.0",
"mquery": "3.2.2",
"ms": "2.1.2",
"regexp-clone": "1.0.0",
"safe-buffer": "5.1.2",
"sift": "7.0.1",
"sliced": "1.0.1"
},
"dependencies": {
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha1-0J0fNXtEP0kzgqjrPM0YOHKuYAk="
}
}
},
"mongoose-legacy-pluralize": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz",
"integrity": "sha1-O6n5H6UHtRhtOZ+0CFS/8Y+1Y+Q="
},

Related

React/Rails app: webpack Webpacker::Manifest::MissingEntryError

I have looked through and tried all of the existing solutions on Stack Overflow. I have:
changed my node version
installed rails:webpacker over and over
deleted node_modules and public/packs folder
ran yarn install, bundle
but I keep getting this error:
Webpacker::Manifest::MissingEntryError
Webpacker can't find hello_react in .../public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}
The line giving an error:
<%= javascript_pack_tag 'hello_react' %>
My versions:
node: v16.14.2
Rails 6.0.6
my package.json:
{
"name": "appname",
"private": true,
"dependencies": {
"#babel/preset-react": "^7.18.6",
"#rails/actioncable": "^6.0.0",
"#rails/activestorage": "^6.0.0",
"#rails/ujs": "^6.0.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"turbolinks": "^5.2.0",
"webpack": "4.46.0"
},
"version": "0.1.0",
"devDependencies": {
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.11.1"
}
}
I cannot move past this error, what am I missing?

Travis CI showing build error for my expressjs app despite showing all tests passed

I have integrated Travis CI into my github repo called Banka which contains expressjs application and some html and css files.
On building, travis shows all my test which I wrote in mocha and chai as passing but yet it finally reports "build error" and surprisingly enough, can't point where the error is.
I changed to latest node and npm versions and still, no change
--package.json
{
"name": "Banka",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node ./bin/www",
"test": "mocha"
},
"engines": {
"node": "~10.15.3",
"npm": "~6.4.1"
},
"dependencies": {
"bcrypt": "^3.0.5",
"body-parser": "~1.8.1",
"chai": "^4.2.0",
"chai-http": "^4.2.1",
"cookie-parser": "~1.3.3",
"debug": "~2.0.0",
"dotenv": "^1.2.0",
"express": "~4.9.0",
"express-jwt": "^3.0.1",
"jade": "~1.6.0",
"jsonwebtoken": "^5.0.2",
"mocha": "^6.1.2",
"morgan": "~1.3.0",
"passport": "^0.2.2",
"passport-local": "^1.0.0",
"request": "~2.51.0"
}
}
Here is what Travis is showing : https://travis-ci.com/NawasNaziru/Banka/builds/108177363
I expect to see "build passing" since, all my tests passed.
The cause of the problem is that mocha doesn't close and handover to Travis after running the written tests. Hence, the reason why, travis reports timeout. To fix that, simply add the --exit flag in your package.json next to mocha like this
{
"test" : "mocha --exit"
......
}

how to have same package-lock.json for all node / npm versions

Is it possible to have different node versions (lts and current) and have the same package-lock.json?
Currently when I run npm install the packages it generates are different to those specified in the package-lock.json file.
For example I'm using nvm (node version manager) to test different node versions on the same machine.
nvm exec v10.3.0 npm i outputs package-lock.json :
"babel-generator": {
"version": "6.26.1",
"resolved": "https://registry.npmjs.org/babel-generator/-/babel-generator-6.26.1.tgz",
"integrity": "sha512-HyfwY6ApZj7BYTcJURpM5tznulaBvyio7/0d4zFOeMPUmfxkCjHocCuoLa2SAGzBI8AREcH3eP3758F672DppA==",
"dev": true,
"requires": {
"babel-messages": "^6.23.0",
"babel-runtime": "^6.26.0",
"babel-types": "^6.26.0",
"detect-indent": "^4.0.0",
"jsesc": "^1.3.0",
"lodash": "^4.17.4",
"source-map": "^0.5.7",
"trim-right": "^1.0.1"
}
},
nvm exec v8.11.2 npm i outputs package-lock.json :
"babel-generator": {
"version": "6.26.1",
"resolved": "https://registry.npmjs.org/babel-generator/-/babel-generator-6.26.1.tgz",
"integrity": "sha512-HyfwY6ApZj7BYTcJURpM5tznulaBvyio7/0d4zFOeMPUmfxkCjHocCuoLa2SAGzBI8AREcH3eP3758F672DppA==",
"dev": true,
"requires": {
"babel-messages": "6.23.0",
"babel-runtime": "6.26.0",
"babel-types": "6.26.0",
"detect-indent": "4.0.0",
"jsesc": "1.3.0",
"lodash": "4.17.10",
"source-map": "0.5.7",
"trim-right": "1.0.1"
}
},
And because of that a lot of git conflicts keep happening between these two version.
Is there any configuration in package.json to have same output for package-lock.json ?

Travis give error but compiles on pc

I'm making a web server with Node.JS and use Travis-Ci to check my code. Yhe problem I got is when I commit my code, Travis gives error below, but the code compiles without an error on my pc:
./backend/server.js: 1: Syntax error: ( unexpected
Here you could find my .travis.yml file:
install:
- npm install
- npm install -g bower
- bower install bootstrap
- bower install socket.io
language: node_js
node_js:
- "6.9"
before_script:
- chmod 0777 ./backend/server.js
cache:
directories:
- node_modules
- bower_components
and the package.json
{
"name": "watchfriends",
"version": "0.0.0",
"description": "Front-end and back-end project watchfriends",
"main": "gulpfile.js",
"scripts": {
"test": "./backend/server.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/WatchFriends/Backend.git"
},
"author": "Hein P., Jasper D., Michiel V., Michiel Z.",
"license": "ISC",
"bugs": {
"url": "https://github.com/WatchFriends/Backend/issues"
},
"homepage": "https://github.com/WatchFriends/Backend#readme",
"devDependencies": {
"gulp": "^3.9.1",
"gulp-autoprefixer": "^3.1.1",
"gulp-clean-css": "^2.0.13",
"gulp-concat": "^2.6.1",
"gulp-csslint": "^1.0.0",
"gulp-htmlhint": "^0.3.1",
"gulp-jshint": "^2.0.4",
"gulp-notify": "^2.2.0",
"gulp-sass": "^2.3.2",
"gulp-sourcemaps": "^2.2.0",
"gulp-uglify": "^2.0.0",
"jshint-stylish": "^2.2.1"
},
"dependencies": {
"socket.io": "^1.5.1"
}
}
On this gist, you could find my code, including the log.
Did I something wrong?
Thanks in advance.
Travis runs npm test when testing your code.
If you check inside of your "package.json" file then you can see that the test script is set to run ./backend/server.js. You need to run the node file with node.
Change that to node ./backend/server.js and hopefully that'll work.

Difference between require and remote.require?

What is the difference between require and remote.require as below
var path = require('path');
const remote =require('remote');
var fsPlus =remote.require('fs-plus');
I have find something for require and remote.require, maybe it is correct:
require is use to get Npm packages
and remote.require is to access remotely defined packages in packages.json file of dependencies part.
for example
{
"name": "Test",
"description": "TestA modern parcel terminal",
"version": "0.1.47",
"main": "main.js",
"dependencies": {
"edge-atom-shell": "^5.0.1",
"finalhandler": "^0.5.0",
"nconf": "^0.8.4",
"fs-plus": "^2.9.2",
"fs-extra": "^0.30.0",
"py-logging": "^0.8.1",
"serve-static": "^1.11.1",
"server-destroy": "^1.0.1"
}
}

Resources