Home > Blockchain >  Which command to use for "compiling" a new NPM project?
Which command to use for "compiling" a new NPM project?

Time:06-22

I'm making a simple JS website using Three.js. I started my project this way:

$ npm init
$ npm install three

Where should I write my code that uses Three.js, and what is the npm command I should run to "compile" my script for something to drop in my webserver public_html?

CodePudding user response:

1 - Run "npm init", it will create package.json file in your package/project directory.

2 - Run "npm install three", it will install the external package and download it into "node_modules" folder.

3 - Create your own .js file. Example {in your package directory}/<yourMainFile>.js. Ensure in the package.json, you change the following attribute "main": "<yourMainFile>.js".

4 - Refer to "three" package usage in https://www.npmjs.com/package/three. and then write the sample code in <yourMainFile>.js

5 - If you want to test the result, run: $ node ./<yourMainFile>.js

  • Use "./" if git bash cli.

6- If inside <yourMainFile>.js file contain console.log("hello or what ever result you want to display"), then you will see the text display in the console.

  • Related