Troubles encountered in transferring arguments from npm command line to package.json using a bash script

This is a different question compared to this particular thread.

I am in search of the optimal method to input command line arguments into my package.json file and npm scripts without necessarily passing it directly into a script.

While there are queries on this topic, none of them specifically deal with the challenges associated with employing a bash function in the package.json file.

The npm script in question looks like this:

"Gocommit": "f() { cd dev; git add -A; git commit -m '$1'; git push;}; f"

What I intend is to be able to execute something like...

npm run Gocommit message

or

npm run Gocommit -- message

And have the flag or argument serve as the commit message.

However, the output continues to use $1 instead.

Where did I make an error?

Answer №1

Here are the two modifications I implemented to rectify the issue.

  1. Relocated the bash script file to another directory

The updated Npm script reads as follows: sh script.sh

Secondly, there is no longer a need for the function wrap in the .sh script or the quotes.

The final script now looks like this:

cd dev; git add -A; git commit -m "$*"; git push;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What sets apart a node.js express route from a controller in terms of functionality and purpose?

Are there any advantages or added power to using a traditional controller instead of an express route? If you have an express app and define models, does it automatically become an MVC application, or are there further steps needed? I can't help but ...

Connecting to a node using VSCode and grunt-contrib-connectConnecting to a node through VSCode

I'm encountering an issue while attempting to debug my node application in Visual Studio Code. The configuration in my .vscode/launch.json file is as follows: { "version": "0.2.0", "configurations": [{ "name": "Attach", "type": "node", ...

The response header Set-Cookie fails to create a cookie in the browser

I'm facing an issue with setting a cookie post user login. The problem seems to occur only in production environment. Upon hitting the /login endpoint, a cookie is returned with a token and other necessary information. if (isPasswordValid === true) { ...

Automatically use JavaScript to send an email to my email address

I have a question I'm trying to solve: Is there a way to send myself an email notification (using a different address) when a specific event occurs in Javascript or Node.js? For example: if (100 > 90) { emailto="xxxxx.gmail.com" subject="It happ ...

Publishing on Npm necessitated my presence being logged in despite the fact that I was already logged in

I've been encountering some issues with deploying my npm package. Initially, I deployed it manually by running 'npm publish' and everything went smoothly, with the package being successfully published. However, I wanted the package to be aut ...

Cannot locate a compatible version for @babel/traverse@^7.14.0

After attempting to clone a project and running npm install, I encountered the following error: npm ERR! code ETARGET npm ERR! notarget No matching version found for @babel/traverse@^7.14.0. npm ERR! notarget In most cases you or one of your dependencies a ...

I am currently struggling with the mapquest GeoJson integration within my Node/Express application. I keep encountering an error message that reads "body used already."

I attempted to utilize the mapquest API by following the provided documentation, however I encountered an error message: HttpError: body used already for: Below is my geoCoder.js configuration: const NodeGeocoder = require('node-geocoder'); con ...

Utilizing JavaScript functions alongside a button within a Handlebars template

My handlebars project has the following structure: Project | +-- server.js +-- package.json +-- package-lock.json | +-- public | | | |-- css | | | + -- style.css | +-- views | | | |-- layouts | | | | | + -- main. ...

Issue with res.format.html not functioning properly in conjunction with the paginate module

I've encountered a problem while using the express-paginate module in my project. The issue seems to be related to the res.format section within my routes file, as it's causing the paginate function to not be found when rendering the view file. ...

Improving JavaScript function by restructuring and eliminating conditional statements from within a loop

Looking for advice on how to refactor my function and eliminate the if statement inside the loop. Any suggestions would be helpful as I suspect the else condition is unnecessary. function quantitySum(array) { let sum = 0; for (let i = 0; i < array ...

Is a fresh connection established by the MongoDB Node driver for each query?

Review the following code: const mongodb = require('mongodb'); const express = require('express'); const app = express(); let db; const options = {}; mongodb.MongoClient.connect('mongodb://localhost:27017/test', options, fu ...

Vue.js / Nginx / Node.js - Error 413: Payload Too Big

My frontend is built using Vue.js and is hosted on an nginx server in production. Here's a snippet of my nginx.conf configuration: server { listen 80; server_name localhost; root /usr/share ...

Implementing AWS Cognito SDK in Node.JS

I am currently developing an API server using node.js that relies on AWS Cognito. Previously, we had a working version of this application on the client side, which utilized the AWS SDK. I am now faced with the challenge of migrating this functionality to ...

Attempting to execute npm install for an Odin project task, encountered the error "Module not Found". // A new error has surfaced, continue reading below

Trying to run npm install for the Odin Project JavaScript Fundamentals Part 4 lesson has been quite a challenge. Initially, upon forking and cloning the repository and running npm install as per the instructions, I encountered a permission error. However, ...

Guide on transforming a JSON string into an array of custom objects using the json2typescript NPM module within a TypeScript environment

I am looking to utilize the json2typescript NPM module to convert a JSON string into an array of custom objects. Below is the code I have written. export class CustomObject { constructor(private property1: string, private property2: string, private p ...

Error: The command "vue" is not recognized

I am encountering an issue while trying to set up vue-cli using npm. Each time I check the version, I receive the error message -bash : vue: command not found. Despite my efforts which include uninstalling and reinstalling, as well as referring to resourc ...

Encountered an issue while trying to run the production script. Received an error when attempting to

Encountering a problem when running the command below npm run production Upon executing the command, the following error is displayed: ERROR Failed to compile with 5 errors error in ./resources/assets/sass/app.scss Module build failed: ModuleBuildErro ...

Frisby.js is looking for a valid JavaScript object, but instead received an undefined value

Struggling to launch a new test using the API testing framework Frisby.js. In my previous tests that didn't involve reading reference files from disk, everything ran smoothly and quickly. The samples provided with Frisby also executed accurately. Thi ...

Unexpected token caused by the Async keyword in served content in Electron

Currently, I have a functioning node server that hosts a basic monopoly app, with my electron application simply loading the URL of this server. However, I've encountered a problem related to asynchronous functions present in the front-end JavaScript ...

Utilizing MongoDB Data in an .ejs Template Using Node.js Express

After going through numerous tutorials, I find myself stuck at a point where I am struggling to render all the data written by my express-app into MongoDB in embedded JavaScript. My goal is to display this data in a simple table that always shows the updat ...