How do you run a js file using npm scripts

0 votes

I can't get npm to work. My package.json file has

"scripts": { "build": "build.js" }

and I have a build.js file in the same folder that just console.logs.

When I run

npm run build

I get the error

The system cannot execute the specified program.

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v4.1.1
npm ERR! npm  v3.3.5
npm ERR! code ELIFECYCLE

and if I move the build.js file and change my package.json file to have a subfolder

"scripts": { "build": "build/build.js" }

then I get the error

'build' is not recognized as an internal or external command, operable program or batch file.

What's going wrong?

Oct 12, 2020 in Node-js by kartik
• 37,520 points
11,369 views

1 answer to this question.

0 votes

Hello @kartik,

Try this:

{ "scripts" :
  { "build": "node build.js"}
}

npm run build OR npm run-script build
{
  "name": "build",
  "version": "1.0.0",
  "scripts": {
    "start": "node build.js"
  }
}

npm start

Hope it helps!!
Thank you!!

answered Oct 12, 2020 by Niroj
• 82,840 points

Related Questions In Node-js

0 votes
1 answer

How do you log content of a JSON object in Node.js?

Hello @kartik, Try this one: console.log("Session: %j", session); If the ...READ MORE

answered Jul 16, 2020 in Node-js by Niroj
• 82,840 points
887 views
0 votes
1 answer

How do I uninstall a package installed using npm link?

Hello @kartik, The package can be uninstalled using ...READ MORE

answered Jul 16, 2020 in Node-js by Niroj
• 82,840 points
4,412 views
0 votes
1 answer

How to download a file with Node.js without using third-party libraries?

Hii, You can create an HTTP GET request and pipe ...READ MORE

answered Nov 24, 2020 in Node-js by Niroj
• 82,840 points
1,304 views
0 votes
1 answer

How do I test a single file using Jest?

Hii, All you have to do is chant ...READ MORE

answered Nov 26, 2020 in Node-js by Niroj
• 82,840 points
40,600 views
0 votes
1 answer

jQuery AJAX fires error callback on window unload - how do I filter out unload and only catch real errors?

Hello, In the error callback or $.ajax you have three ...READ MORE

answered Apr 27, 2020 in Java-Script by Niroj
• 82,840 points
4,230 views
0 votes
1 answer

How do I pass command line arguments to a Node.js program?

Hello @kartik, If your script is called myScript.js ...READ MORE

answered May 5, 2020 in Java-Script by Niroj
• 82,840 points
3,278 views
0 votes
1 answer

Error:Issue when trying to use IN() in wordpress database

Hello @kartik, Try this code : // Create an ...READ MORE

answered May 8, 2020 in PHP by Niroj
• 82,840 points
1,149 views
+2 votes
1 answer

How do I debug Node.js applications?

Hello @kartik, Use node-inspector  from any browser supporting WebSocket. Breakpoints, ...READ MORE

answered Jul 8, 2020 in Node-js by Niroj
• 82,840 points
1,049 views
0 votes
1 answer

How do you reinstall an app's dependencies using npm?

Hello @kartik, The easiest way is  to delete node_modules folder ...READ MORE

answered Jul 12, 2020 in Node-js by Niroj
• 82,840 points
2,668 views
0 votes
1 answer

How do I install a module globally using npm?

Hello @kartik, I found the output contained the ...READ MORE

answered Jul 16, 2020 in Node-js by Niroj
• 82,840 points
824 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP