7

Whenever I start my nodejs project, it refers to itself by the old name I gave it:

gpio-editor@0.0.0 start /home/pi/RPi-Computer-Power/RPi-Server

I do not want it to be called gpio-editor anymore, but I have not found a way to change it on the interwebs. I am pretty new to nodejs, and I didn't originally make this project.

If someone knows how to do this, please let me know. Thanks, Neil

Charith
  • 2,640
  • 2
  • 19
  • 24
ifconfig
  • 4,454
  • 7
  • 33
  • 54

3 Answers3

14

Check out package.json. There should be a few properties in there that you can change (you want to change the name). A simple file would look something like this:

{
    "name": "gpio-editor",
    "version": "0.0.0",
    "author": "Sudo Programmer <hi@sudoprogrammer.com>",
    "description": "i use this to edit stuff",
    "license": "pick one",
    "engines": {
        "node": ">=0.10"
    },
    "scripts": {
        "start": "node ./app.js"
    },
    "dependencies": {
        // something or other, don't include comments though
    }
}

Edit (5/31/2018)

Since Node 5 (I believe), the package-lock.json file has been generated and used as an, "I last built this codebase using these dependency versions" tool. The package.json file is supposed to do this, but it doesn't protect you from packages that don't follow semantic versioning. For this reason, I would recommend checking the package-lock.json file in and updating the name there as well. There's some good info on the lock file here.

Matt
  • 1,242
  • 12
  • 23
  • What if there is a `package-lock.json` ? Should the name be manually changed there also? – Marinos An May 31 '18 at 12:49
  • I would. The `package-lock.json` is essentially a, "I built this project with these versions of my dependencies." That is what `package.json` is for, but the lock file will protect you from packages that don't abide by semantic versioning. You should also be checking your lock file into your repo (this will help other users run the code as you have). – Matt Jun 01 '18 at 01:23
4

Edit the name attribute in your package.json, that's what determines the name of your package.

Balázs Édes
  • 12,013
  • 4
  • 45
  • 79
0

if you're copying files from an existing project and still having issues after updating the name attribute in package.json, try npm i or yarn.

tomyhomie
  • 21
  • 3