{"id":20903792,"url":"https://github.com/suyashsingh/nodejs","last_synced_at":"2026-04-27T10:31:17.182Z","repository":{"id":204161433,"uuid":"158665109","full_name":"suyashsingh/nodejs","owner":"suyashsingh","description":"NodeJS Codes","archived":false,"fork":false,"pushed_at":"2018-11-27T10:06:18.000Z","size":338,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-27T20:57:43.102Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/suyashsingh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-11-22T08:18:13.000Z","updated_at":"2018-11-27T10:06:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"2ac4ee8b-8d08-42ad-a00b-68e3aea2ed7d","html_url":"https://github.com/suyashsingh/nodejs","commit_stats":null,"previous_names":["suyashsingh/nodejs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/suyashsingh/nodejs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suyashsingh%2Fnodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suyashsingh%2Fnodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suyashsingh%2Fnodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suyashsingh%2Fnodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/suyashsingh","download_url":"https://codeload.github.com/suyashsingh/nodejs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suyashsingh%2Fnodejs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32333193,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T13:14:59.502Z","updated_at":"2026-04-27T10:31:17.087Z","avatar_url":"https://github.com/suyashsingh.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nodejs\nNodeJS Codes\n\nModules are simalar to libraries in javascript.\nrequire() method is used to include modules in your nodejs code.\n\n\nFiles:\n--------\nThere are the following methods for creating files using the file system module:\n1. fs.appendFile() \n    This method will append data to an existing file. If the file is not available\n    it will be created.\n\n2. fs.open()\n    This method will create a new file is file is not present. Also you have a second\n    arguement that specifies the mode for opening file: eg \"w\"\n\n3. fs.writeFile()\n    This method will create a file for writing if it is not exisitant else the file will\n    be opened and all the content that is in the file will be *REPLACED* with the new content.\n    The fs.appendFile() method on the other hand will be just adding contents to the existing\n    file if it exists.\n\n4. fs.unlink()\n    This method is used to delete a file.\n\n5. fs.rename()\n    This method is used to rename a file.\n\n\n\n\nnodejs packages\n--------\nNPM is the package manager for nodejs.\n* Modules: are js libraries\n\n* Package in nodejs: will contain all the file that you need \n    for module.\n\n* Downloading a package:\n    npm install name-of-package\n    say for example `upper-case`\n\n    When you download a package using npm it will create a folder called `node_modules` \n    in the current directory where you are working.\n\n    Now once you have installed the package you will need to include the package in your nodejs project.\n    You will have to use the same `require()` method that was used earlier.\n\n\nnodejs events\n--------\n\n* Events can be used for firing some function when something happens. For example\nyou can bind an event such that when ever some one tries to open a file you\nput up and alert window, etc.\n\n* nodejs has a built in event module. Using this module you can:\n        - create\n        - listen\n        - fire \n        your events.\n\n* Objects in nodejs can fire events. eg. the readStream object fires events when \nopening or closing a file.\n\n* Using the events module you can create, fire adn listen for your own events. You will have to used to require() method for\nincluding the module.\n\n* Also all event properties and methods are an instance of the\n`EventEmitter` object. So for acessing the event related methods and properties you will need to create an `EventEmitter` object.\n\nFile Upload / Formidable Module\n--------\n\nFormidable is a very good module for uploading files to the server. \nYou will need to download the module using npm. \nThen you will have to require that module in your nodejs code,\nand you are good to go.\n\nWhat is done in this example is that a form is created so\nthat the user can selet the file that he has to upload.\n\nNow when the file reaches the server it is first stored in a\n`temporary folder`. You can change the location of the file\nfrom the temporary location to the location of you choice\nby passing a callback function as the third argumenmt of the\nparse() function.\n\nMySql\n--------\n\n1. Try connecting to the database.(make sure that the database service is running)\n\n2. Creating a Database - use the `CREATE DATABASE` statement to create database.\n\n3. Creating a Table in a database - use the `CREATE TABLE` statment and also mention the\n    name of the database where you want to create the table.\n\n    You should also create provide the primary key for the record. This will make the record unique.\n    You can define of the columns as  `INT AUTO_INCREMENT PRIMARY KEY`. It will start with 1 and keep\n    on increasing as you add more entries to the table.\n\n    If the table is already exsists then you will have to alter the table for adding new column (Which will be your primary key) - `ALTER TABLE customers ADD COLUMN id INT AUTO_INCREMENT PRIMARY KEY`.\n\n4. Inserting data into the table - use the `INSERT INTO` statement.\n\n    You can either insert single record or multiple records at a time.\n\n    For adding multiple records, you will have to make an array containing the values and\n    insert a `?` in the sql query(It will be replaced by the value array).\n\n    *RESULT object*: When you fire a query you will get a result object back. The result object will\n    contain information about how the query affected the table.\n    \n    The result object looks like:\n\n        {\n            fieldCount: 0,\n            affectedRows: 14,\n            insertId: 0,\n            serverStatus: 2,\n            warningCount: 0,\n            message: '\\'Records:14  Duplicated: 0  Warnings: 0',\n            protocol41: true,\n            changedRows: 0\n        } \n\n    For example:\n    \n    - If you insert multiple columns in to the table you can get the number of rows that were added by checking the `affectedRows` column of the records object.\n\n    - Get the id of the row that you have inserted using `insertId` field. \n    \n    \u003e *This will work only for single record operations*\n\n\n5. Selecting data from the table i.e. Quering the data that is in the table - use the `SELECT`      statement.\n\n    - Selecting all columns: `SELECT * FROM table_name`\n\n    - Selecting column name: `SELECT column_1, column_2 from table _name`\n\n\nUpon execution of the `SELECT`statement, you will get a:\n\n    1. `result` object \u0026\n    2. `fields` object  \n\nas result of the query.\n\nThe result object will be an array of objects, with each object denoting a row that was the outcome of your query.\n\nFields object is an array containg information about each field in the result.\n\nYou can also use the `where` statement as a filter to the `select` statment. You can use wild cards, ? placeholder, etc.\n\n*The queries should be escaped using the mysql.escape() method to prevent SQL injection.*\n\n    ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuyashsingh%2Fnodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuyashsingh%2Fnodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuyashsingh%2Fnodejs/lists"}