Need to use a password in package.json - npm

When working locally I start my application with an npm command in my package.json. The problem is that I need this command to include a password for a remote database:
"scripts": {
"start":
"MONGO_URL='mongodb://USERNAME:PASSWORD#URL:PORT/DB-NAME' meteor --settings settings.json"
},
This is working but I dont want to save my password to my source control. How can I run the same command without committing my password?

You can set the environement variable programmaticaly at startup and store the secret in the settings.json file (which is appropriate to store secrets and shouldn't be in version control - see here)
in the startup/server/index.js file:
let mongoPassword = Meteor.settings.private.mongoPassword;
process.env.MONGO_URL = "mongodb://USERNAME:" + mongoPassword + "#URL:PORT/DB-NAME";
You can also choose to start your app using the meteor command and store the MONGO_URL environment variable in your local development environment
In production, you shouldn't use the meteor command but build with meteor build and then run the bundled app with node main.js

Related

How to deploy molecular project without docker in production?

How should I deploy a molecular microservice project on the server without using docker and Kubernetes?
I pull my updated code into a server and run the npm run dev command project run as per aspected.
But now I want to set up pm2 for this project so, what do I need to do?
I try to run npm run start command on a server but I am getting below output and the project is not running.
Please help.
Your problem is that you didn't configure the services to start. For Docker and Kubernetes environment, we use SERVICES env variable to configure what services should be loaded on a Moleculer node.
So you can also use this way, or modify the start script in package.json and set the services what you want to load. E.g.
moleculer-runner -e services/**/*.service.js
I got the solution.
If we not use the Docker and Kubernetes for moleclar project and directly clone our code on server same as like normal NodeJS(Express) project.
Then we need to create index.js file and need to put below lines.
const { ServiceBroker } = require('moleculer');
const config = require('./moleculer.config');
config.hotReload = true;
const broker = new ServiceBroker(config);
broker.loadServices('services', '**/*.service.js');
broker.start();
So, using above command Molecular started all the service of our project
After, index file we can able to start our project using pm2 service.
I created a start script (api-init.json) as below:
[
{
"script": "./node_modules/moleculer/bin/moleculer-runner.js",
"args": "services",
"instances": "max",
"watch": false,
"name": "API"
}
]
Then use pm2 to start:
pm2 start api-init.json

Use NPM publish with Gitlab

I'd make my first npm publish into my Gitlab project. The project is private so I generated a deploy token with read & write permission for package registry.
Locally I created an .npmrc file and used these lines:
#laszlo-bottlik:registry=https://gitlab.com/api/v4/projects/28303714/packages/npm/
//gitlab.com/api/v4/packages/npm/:_authToken='<deploy-name>:<deploy-password>'
//gitlab.com/api/v4/projects/28303714/packages/npm/:_authToken='<deploy-name>:<deploy-password>'
Name value in package json is #laszlo-bottlik/playground
Url for the project is https://gitlab.com/laszlo-bottlik/playground
When I run npm publish command in terminal then I get 401 error:
HttpErrorGeneral: 401 Unauthorized - PUT https://gitlab.com/api/v4/projects/28303714/packages/npm/#laszlo-bottlik%2fplayground
Any kind of help can lead me to the solution.
What should I check in my local environment?
What should I check in my project settings under Gitlab?
Is there a reason you're using a deploy token as opposed to a job token? Either way, it looks like you may have an extra variable in your authToken argument above - You have <deploy-name>:<deploy-password> in your example code, but GitLab's code only shows a single auth_token argument (reference):
npm config set -- '//gitlab.example.com/api/v4/projects/<your_project_id>/packages/npm/:_authToken' "<your_token>"

Vue-CLI v3 app: hot module reload not working

I've installed Vue CLI v3, and in my terminal:
created a new app using 'vue create my-project' (accepting default config)
navigated to the 'my-project' app directory and run 'npm run serve', the result of which is:
DONE Compiled successfully in 11889ms
App running at:
- Local: http://localhost:8080/
- Network: http://192.168.0.3:8080/
Note that the development build is not optimized. To create a production build, run npm run build.
... and then, when making any change whatsoever to the Hello World component, e.g., a tweak to the css, something obvious like the link color, nothing happens; no response in the terminal, no browser refresh, and no update to the page when manually refreshing.
I've built a few apps using Vue in the past, hot module reloading was working previously, but now there is zero activity/response in the terminal regardless of what I change in any project file; only if I close the terminal tab, re-open a tab, navigate to the project directory and re-run 'npm run serve', and refresh the browser do I see the changes. obviously this is unusable. What am I missing?
This issue has been resolved, though I am not 100% sure what caused it.
I noticed that some people with similar failures of hot reload had mentioned bad directory names. My vue project's parent directory name was legit but I had renamed it at one point (though that was multiple restarts and reinstalls ago), and I also noticed that some of the vue-cli-created project folders were not displaying in the Finder until it was quit and restarted. I figured there was something corrupted about that folder. I created a new folder - a sibling of the dubious folder - and had another go with vue-cli, and it worked as expected.
Hope this helps someone. Thanks again to those of you who offered suggestions.
Whiskey T.
For anyone using WSL. I ran into this exact problem and solved it via this method.
I had the same issue, It seems wsl2 does not watch for file changes
inside the windows filesystem. Everything works fine if the vue
project is inside the Ubuntu filesystem. Check out this link for
further info
https://learn.microsoft.com/en-us/windows/wsl/wsl2-ux-changes.
Source: https://github.com/vuejs/vue-cli/issues/4421#issuecomment-557194129
If u installed Node js as sudo, then Running sudo npm run serve worked for me. Actually node.js was installed as sudo and the project also created as sudo so when I run npm run serve the vue-hot-reload-api cannot access the node server to do hot reload
Additionally if u want the hot reload to work in offline mode, then switch off your network and then npm run serve and then reconnect to your network. That will work as localhost protocol and not use your local network IP.
Cheers
Add following script tag to package.json file
...
"scripts": {
"dev": "cross-env NODE_ENV=development vue-cli-service serve --open --host localhost",
....
},
....
and run with
npm install –save-dev cross-env
npm run dev
source: https://www.davidyardy.com/blog/vue-cli-creating-a-project%E2%80%93issue-with-hot-reload/

How can I set up TestCafe to run on an environment specified in the CLI?

How can I set up TestCafe to run on an environment specified in the CLI?
For example
testcafe chrome test.js --env=development
I want to set up a list of different environments - such as development, integration, etc - in which I can call in the CLI when running the tests.
Is there a default set-up of this in the config?
Does anyone have an example?
TEST_ENV=development npm run test:firefox
Above is the command to run test.
Use this environment variable via process.env.Test_ENV, wherever you need to pass 'development' or any other environment as value. The script,
"scripts": {
"test:firefox": "testcafe firefox ./tests"}

backand platform: how debug server platform code localy

The documantion mention that there is a way to develop entire project localy and then upload it to back& platform for production. how can it be done?
There is sample code somewhere ?
thanks
The server side in Back& can be built with cloud JavaScript or with node.js.
Using Backand CLI and node.js you can develop any project in node.js and upload it.
The steps are simple:
Create new action with "Server side node.js code"
Run the action.init command (copy paste from the action page)
Use the backand shell project to build the node.js project
Run action.deploy command to upload and run the code on the server
for debug node.js localy :
first make sure you have action defind in the back& site under the section objects/[objectName]/action
example:
project name: MyApp
with object call: Users
with the action files (for upload a images file)
so
In local terminal
1. go to project's root folder.
2. type backand login and follow the instraction (email & password).
3. type backand action init and follow the instration.
project name : MyApp,
object name : Users,
action name : files
to be continue...