Heroku can't find ExpressJS/Knex migrations - postgresql

I have an Express.js api that works locally, using Postgresql via Knex/SQL queries.
I am trying to deploy to Heroku, however, when I attempt to migrate the DB I get the error that Heroku can't find the migration files.
Specifically, when I run the migration it throws:
Using environment: production Error: ENOENT: no such file or
directory, scandir '/app/migrations'
My migrations are located at my_app/db/migrations. The app folder mentioned in the error does not exist. Trying to figure out how to point to the correct folder.
Here is my package.json:
{
"name": "writerboard-express-api",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "cross-env NODE_ENV=development nodemon server.js"
},
"keywords": [],
"author": "dariusgoore <dariusgoore#gmail.com> (dariusgoore.com)",
"license": "MIT",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"dotenv": "^8.1.0",
"express": "^4.17.1",
"express-jwt": "^5.3.1",
"jsonwebtoken": "^8.5.1",
"knex": "^0.19.3",
"objection": "^1.6.9",
"objection-password": "^2.0.0",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"pg": "^7.12.1"
},
"devDependencies": {
"cross-env": "^5.2.1",
"nodemon": "^1.19.1"
}
}
My knexfile (myapp/knexfile.js):
const dotenv = require('dotenv');
dotenv.config({ path: "../.env" });
module.exports = {
development: {
client: 'postgresql',
connection: {
database: 'writerboard_dev', // update with env var
user: 'dariusgoore' // update with env var
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations',
directory: './db/migrations'
},
seeds: {
directory: './db/seeds'
}
},
production: {
client: 'postgresql',
connection: process.env.DATABASE_URL,
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations'
},
ssl: true
}
};
here is the server log from heroku:
2019-09-16T14:25:00.251226+00:00 heroku[web.1]: State changed from down to starting
2019-09-16T14:25:00.063523+00:00 app[api]: Release v8 created by user dariusgoore#gmail.com
2019-09-16T14:25:00.063523+00:00 app[api]: Deploy b697b243 by user dariusgoore#gmail.com
2019-09-16T14:25:00.000000+00:00 app[api]: Build succeeded
2019-09-16T14:25:03.700742+00:00 heroku[web.1]: Starting process with command `node server.js`
2019-09-16T14:25:08.369304+00:00 heroku[web.1]: State changed from starting to up
2019-09-16T14:25:07.885086+00:00 app[web.1]: Running on localhost:58146

FYI, the answer was in the knexfile.js. Needed to set the migrations directory for production.

Related

Error: Jest: Got error running globalSetup ../#shelf/jest-mongodb/setup.js, reason: Instance Exited before being ready and without throwing an error

I'm following the documentation on jestjs.io. When I try to run a test I get this error:
Error: Jest: Got error running globalSetup - /home/.../node_modules/#shelf/jest-mongodb/setup.js, reason: Instance Exited before being ready and without throwing an error!
This happened both when I've used typescript and also when I created a simple app using javascript instead:
package.json:
{
"name": "mongojest",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"#shelf/jest-mongodb": "^3.0.1"
},
"scripts": {
"test": "jest"
},
"dependencies": {
"jest": "^28.1.0"
}
}
jest.config.js:
module.exports = {
coverageProvider: "v8",
"preset": "#shelf/jest-mongodb"
};
I haven't made any changes other than the minimum installs to get it running.
I got around this issue by installing Ubuntu 20.04. I was using the newer Ubuntu 22.04 and it seem to have caused some issues.
I installed typescript in my project. That was enough to run. Follow my configuration files
//package.json
{
"name": "research-with-programmers-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest --passWithNoTests --silent --noStackTrace --runInBand",
"test:verbose": "jest --passWithNoTests --runInBand",
"test:unit": "yarn test -- --watch -c jest-unit-config.ts",
"test:integration": "yarn test -- --watch -c jest-integration-config.ts",
"test:staged": "yarn test -- --findRelatedTest",
"test:ci": "yarn test -- --coverage"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#shelf/jest-mongodb": "^4.1.0",
"#types/bcrypt": "^5.0.0",
"#types/jest": "^28.1.8",
"#types/mongodb": "^4.0.7",
"#types/node": "^18.7.13",
"#types/validator": "^13.7.6",
"#typescript-eslint/eslint-plugin": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-standard-with-typescript": "^22.0.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-promise": "^6.0.0",
"git-commit-msg-linter": "^4.1.3",
"husky": "^8.0.1",
"jest": "^29.0.1",
"lint-staged": "^13.0.3",
"ts-jest": "^28.0.8",
"ts-node": "^10.9.1",
"typescript": "^4.8.2"
},
"dependencies": {
"bcrypt": "^5.0.1",
"mongodb": "^4.10.0",
"validator": "^13.7.0"
}
}
//jest-config.ts
export default {
roots: ['<rootDir>/src'],
collectCoverageFrom: [
'<rootDir>/src/**/*.ts',
'!<rootDir>/src/**/protocols/*.ts',
'!<rootDir>/src/**/*protocols.ts',
'!<rootDir>/src/**/models/*.ts',
'!<rootDir>/src/**/usecases/*.ts',
'!<rootDir>/src/**/index.ts'
],
collectCoverage: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',
testEnvironment: 'node',
preset: '#shelf/jest-mongodb',
transform: {
'.+\\.ts$': 'ts-jest'
}
}
// jest-mongodb-config.ts
export default {
mongodbMemoryServerOptions: {
instance: {
dbName: 'jest'
},
binary: {
version: '4.0.3',
skipMD5: true
},
autoStart: false
}
}

how to solve mongoParseError in nodeModule?

this is output after run yarn start having this is the error:
`yarn run v1.22.17
warning ../../../package.json: No license field
$ ts-node index.ts
MongoParseError: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"
at new ConnectionString (/Users/youmnasalloum/Desktop/ts/user/node_modules/mongodb-connection-string-url/src/index.ts:133:13)
at parseOptions (/Users/youmnasalloum/Desktop/ts/user/node_modules/mongoose/node_modules/mongodb/src/connection_string.ts:253:15)
at new MongoClient (/Users/youmnasalloum/Desktop/ts/user/node_modules/mongoose/node_modules/mongodb/src/mongo_client.ts:337:34)
at /Users/youmnasalloum/Desktop/ts/user/node_modules/mongoose/lib/connection.js:783:16
at new Promise (<anonymous>)
at NativeConnection.Connection.openUri (/Users/youmnasalloum/Desktop/ts/user/node_modules/mongoose/lib/connection.js:780:19)
at Mongoose.createConnection (/Users/youmnasalloum/Desktop/ts/user/node_modules/mongoose/lib/index.js:285:10)
at Object.<anonymous> (/Users/youmnasalloum/Desktop/ts/user/db/index.ts:9:28)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Module.m._compile (/Users/youmnasalloum/Desktop/ts/user/node_modules/ts-node/src/index.ts:1455:23)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
make: *** [start] Error 1`
this is package.json:
{ "name": "user", "version": "1.0.0", "main": "index.ts", "repository": "https://github.com/ArtistCrowdfundExchange/user", "author": "Oghogho Odemwingie", "license": "MIT", "devDependencies": { "#types/bcrypt": "^3.0.0", "#types/node": "^17.0.13", "typescript": "4.5.5" }, "scripts": { "start": "ts-node index.ts", "test": "echo no tests yet" }, "dependencies": { "#aws-sdk/client-s3": "^3.41.0", "#grpc/grpc-js": "^1.3.7", "amqp": "^0.2.7", "aws4": "^1.11.0", "bcrypt": "^5.0.0", "cuid": "^2.1.8", "encrypter": "^1.0.0", "erax.db": "^3.3.1", "jose": "3", "mongodb": "^4.5.0", "mongodb-uri": "^0.9.7", "mongoose": "6.1.8", "nanoid": "^3.1.29", "proto": "git+https://github.com/ArtistCrowdfundExchange/proto#playground", "ts-node": "^10.4.0", "winston": "^3.3.3", "yael-autoencrypt": "^1.1.0" } }
I tried to add packages mongo-Uri,mongo-connection-string-URI using yarn but still the same error when I do yarn start

Facing issue, when serenity js library is included for Cucumber protractor typescript tests

I am learning Cucumber BDD with serenity js library for reporting purpose off Angular website . I am using Type script as programming language.
I am able to generate the cucumber report for different feature file scenarios. But when i am trying to include the serenity library for report enhancement, i am facing the below issue. -
Issue is :
PS R:\protractor\protractor-cucumber-typescript> tsc
PS R:\protractor\protractor-cucumber-typescript> npm test
> protractor-typescript-cucumber#3.0.0 pretest R:\protractor\protractor-cucumber-typescript
> serenity update
info: Serenity BDD CLI jar file is up to date :-)
> protractor-typescript-cucumber#3.0.0 test R:\protractor\protractor-cucumber-typescript
> protractor typeScript/config/config.js
[15:29:46] I/launcher - Running 1 instances of WebDriver
[15:29:46] I/hosted - Using the selenium server at http://127.0.0.1:4444/wd/hub
[15:29:54] E/launcher - Error: TypeError: Path must be a string. Received true
at assertPath (path.js:7:11)
at Object.basename (path.js:801:5)
at R:\protractor\protractor-cucumber-typescript\node_modules\cucumber\lib\cucumber\cli\configuration.js:11:27
at Array.forEach (native)
at Function.Configuration (R:\protractor\protractor-cucumber-typescript\node_modules\cucumber\lib\cucumber\cli\configuration.js:10:10)
at getConfiguration (R:\protractor\protractor-cucumber-typescript\node_modules\cucumber\lib\cucumber\cli.js:63:38)
at Object.run (R:\protractor\protractor-cucumber-typescript\node_modules\cucumber\lib\cucumber\cli.js:69:27)
at R:\protractor\protractor-cucumber-typescript\node_modules\serenity-js\src\serenity-cucumber\cucumber_test_framework.ts:24:51
at CucumberTestFramework.run (R:\protractor\protractor-cucumber-typescript\node_modules\serenity-js\src\serenity-cucumber\cucumber_test_framework.ts
:21:16)
at R:\protractor\protractor-cucumber-typescript\node_modules\serenity-js\src\serenity-protractor\framework\serenity_protractor_framework.ts:52:35
[15:29:54] E/launcher - Process exited with error code 100
npm ERR! Test failed. See above for more details.
Its not giving any traces of the files i have. Its showing me a different file.
Serenity dependency got downloaded, But when the protractor conf.js file run. I am getting above issue
Files look like below -
Conf.ts file looks like below :
import * as path from "path";
import { browser, Config } from "protractor";
const crew = require('serenity-js/lib/stage_crew');
export const config: Config = {
seleniumAddress: "http://127.0.0.1:4444/wd/hub",
SELENIUM_PROMISE_MANAGER: false,
// baseUrl: "http://www.google.com",
baseUrl2: "https://angularjs.org/",
framework: "custom",
frameworkPath: require.resolve('serenity-js'),
specs: [
"../../features/*Home.feature",
],
cucumberOpts: {
// require: ["../../stepdefinitions/*.ts","../../support/stepdefinitions/*.js"],
require: ["stepdefinitions/*/**.ts","support/stepdefinitions/*/**.js"],
// strict: true,
format: "pretty",
compiler: "ts:ts-node/register",
},
serenity: {
dialect: 'cucumber',
crew: [
crew.serenityBDDReporter(),
crew.photographer(),
crew.consoleReporter()
]
},
capabilities: {
browserName: "chrome",
},
onPrepare: () => {
browser.ignoreSynchronization = true;
browser.manage().window().maximize();
browser.get("https://angularjs.org/");
},
};
My package.json file looks like below :
{
"name": "protractor-typescript-cucumber",
"keywords": [
"protractor",
"cucumber",
"typescript",
"angular",
"angularjs",
"testing",
"behaviour driven development",
"bdd",
"selenium",
"webdriverJS",
"gherkin",
"automation testing"
],
"main": "index.js",
"scripts": {
"build": "tsc",
"clean": "rimraf typeScript/",
"clean-build": "npm run clean && npm run build",
"test": "protractor typeScript/config/config.js",
"webdriver-update": "webdriver-manager update",
"webdriver-start": "webdriver-manager start",
"pretest": "serenity update",
"report": "serenity run"
},
"devDependencies": {
"#types/cucumber": "^2.0.4",
"#types/node": "^8.0.3",
"#types/selenium-webdriver": "^3.0.7",
"chai": "^4.0.2",
"chai-as-promised": "^7.0.0",
"chai-smoothie": "^0.3.2",
"cucumber": "1.3.2",
"cucumber-html-reporter": "^3.0.4",
"mkdirp": "^0.5.1",
"protractor": "^5.1.2",
"protractor-cucumber": "^0.1.8",
"protractor-cucumber-framework": "^4.0.8",
"rimraf": "^2.6.2",
"serenity-cli": "^0.2.4",
"serenity-js": "^1.4.1",
"standard-loader": "^6.0.1",
"ts-node": "^3.3.0",
"typescript": "^2.5.3"
},
"dependencies": {
"#types/chai": "^4.0.4"
}
}
Please update me, where i am going wrong

How to interact with Windows Authentication and Users group using React.js .Net

I am curious how one would interact with Windows Authentication using React.js.
We have a little internal portal we are trying to set up, we already have predefined users groups and users that are in them. We are looking for a way to get those Authenticated credentials to the view using React.js. There are a couple of good links on how to get started with Reactjs.net but I don't see any tutorials on passing credentials to Reactjs.
Any suggested reading? Tutorials or maybe you know yourself and can provide direction?
enter link description here
I've found this really cool tutorial!
It says:
Here’s a minimal setup for React and Webpack based on what we did in this article. Now that you understand the steps, you can copy-paste this to your heart’s content.
package.json
Note: agentkeepalive is only needed for fixing a Windows authentication error with Hot Module Replacement.
{
"name": "ReactWebPackMVC5",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack",
"dev": "webpack-dev-server –open –hot"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.0.0",
"#babel/preset-env": "^7.0.0",
"#babel/preset-react": "^7.0.0",
"agentkeepalive": "^3.5.1",
"babel-loader": "^8.0.2",
"react": "^16.5.0",
"react-dom": "^16.5.0",
"webpack": "^4.18.0",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.8"
}
}
webpack.config.js
Again, agentkeepalive is only needed for fixing a Windows authentication error with Hot Module Replacement. The same is true for the agent and onProxyRes properties.
const path = require("path"); const agent = require("agentkeepalive")
module.exports = { mode: "development", entry: "./Scripts/react/app.js", //or app.jsx output: { path: path.resolve(__dirname, "./Scripts/react/dist"), filename: "bundle.js", publicPath: "Scripts/react/dist" }, resolve: { extensions: ["*", ".js", ".jsx"] }, module: { rules: [ { test: /\.(js|jsx)/, exclude: /node_modules/, use: { loader: "babel-loader", options: { “presets”: [“#babel/preset-env”, “#babel/preset-react”] } } } ] }, devServer: { proxy: { "*": { target: "http://localhost:59829", changeOrigin: true, agent: new agent({ maxSockets: 100, keepAlive: true, maxFreeSockets: 10, keepAliveMsecs: 100000, timeout: 6000000, keepAliveTimeout: 90000 // free socket keepalive for 90 seconds }), onProxyRes: (proxyRes) => { var key = "www-authenticate"; proxyRes.headers[key] = proxyRes.headers[key] && proxyRes.headers[key].split(","); }, }, port: 8080, host: "0.0.0.0", hot: true, }, } };

Getting "connect ECONNREFUSED" error when I "npm run seed" in feathers api with mongodb

I'm learning react and feathers. For my recipes app that I've made in react I use feathers api and mongodb. I have some seeds as examples in /src/seeds.js and just began to set up everything in feathers but when I want to run my seeds(npm run seed) and check if it works on feathers localhost:3030/recipes I got this error:
Error creating user! { Error: connect ECONNREFUSED 127.0.0.1:3030
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3030,
response: undefined }
I don't know the error is because of connection or creating user!
I checked my mondo db, it runs.
this is package.json, just in case:
{
"name": "recipes-api(par)",
"description": "api for recipes app",
"version": "0.0.0",
"homepage": "",
"main": "src/",
"keywords": [
"feathers"
],
"license": "MIT",
"repository": {},
"author": {},
"contributors": [],
"bugs": {},
"engines": {
"node": ">= 0.12.0"
},
"scripts": {
"test": "npm run jshint && npm run mocha",
"jshint": "jshint src/. test/. --config",
"start": "node src/",
"mocha": "mocha test/ --recursive",
"seed": "node src/seeds.js"
},
"dependencies": {
"body-parser": "^1.17.1",
"compression": "^1.6.2",
"cors": "^2.8.3",
"feathers": "^2.1.1",
"feathers-authentication": "^0.7.12",
"feathers-client": "^2.2.0",
"feathers-configuration": "^0.3.3",
"feathers-errors": "^2.6.3",
"feathers-hooks": "^1.8.1",
"feathers-mongoose": "^3.6.2",
"feathers-rest": "^1.7.2",
"feathers-socketio": "^1.6.0",
"mongoose": "^4.9.6",
"passport": "^0.3.2",
"serve-favicon": "^2.4.2",
"superagent": "^3.5.2",
"winston": "^2.3.1"
},
"devDependencies": {
"jshint": "^2.9.4",
"mocha": "^3.3.0",
"request": "^2.81.0"
}
}
Before adding seeds I should have seen {"total":0,"limit":5,"skip":0,"data":[]} in http://localhost:3030/recipes that I'm still having it but after running seeds I should see the list of my recipes.
Anythings else that I need to copy here from my code? any idea?