Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename nodejs project?

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

like image 918
ifconfig Avatar asked May 25 '17 16:05

ifconfig


People also ask

How do I change the project name in node?

Edit the name attribute in your package. json , that's what determines the name of your package. Save this answer. Show activity on this post.

How do I rename a folder in node JS?

fs.rename() method accepts two arguments, the current folder name you want to rename and the new folder name, and asynchronously renames the folder. Here is an example: const fs = require('fs') // directory paths const oldDirName = './images' const newDirName = './img' // rename the directory fs.

How do I rename a file in FS module?

js using fs module. Node FS Rename File – To rename file with Node FS, use fs. rename(new_file_name, old_file_name, callback_function) for asynchronous file rename operation and use fs. renameSync(new_file_name, old_file_name) for synchronous file rename operation.


2 Answers

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 <[email protected]>",
    "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
    }
}

After that you should run npm install, which will update the file package-lock.json accordingly.

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.

like image 199
Matt Avatar answered Nov 03 '22 01:11

Matt


if you're copying files from an existing project and still having issues after updating the name attribute in package.json, try removing node_modules dir and package-lock.json file (backup if needed) and run npm i or yarn.

like image 32
tomyhomie Avatar answered Nov 03 '22 01:11

tomyhomie