{"id":17897246,"url":"https://github.com/tigoe/nodeexamples","last_synced_at":"2025-04-13T06:41:23.515Z","repository":{"id":24947554,"uuid":"28365215","full_name":"tigoe/NodeExamples","owner":"tigoe","description":"a bunch of node.js examples","archived":false,"fork":false,"pushed_at":"2024-10-30T10:16:51.000Z","size":1987,"stargazers_count":31,"open_issues_count":3,"forks_count":37,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-24T11:43:40.489Z","etag":null,"topics":["javascript","nodejs"],"latest_commit_sha":null,"homepage":"https://tigoe.github.io/NodeExamples/","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/tigoe.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-12-22T23:28:29.000Z","updated_at":"2024-10-30T10:16:54.000Z","dependencies_parsed_at":"2024-10-28T15:27:39.008Z","dependency_job_id":"569764b6-4b0d-4995-a615-b3b8a00faf61","html_url":"https://github.com/tigoe/NodeExamples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigoe%2FNodeExamples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigoe%2FNodeExamples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigoe%2FNodeExamples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tigoe%2FNodeExamples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tigoe","download_url":"https://codeload.github.com/tigoe/NodeExamples/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675434,"owners_count":21143763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["javascript","nodejs"],"created_at":"2024-10-28T15:08:32.476Z","updated_at":"2025-04-13T06:41:23.493Z","avatar_url":"https://github.com/tigoe.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node Examples\n\nThis is a collection of examples for node.js and express.js. Includes a short [intro to JavaScript patterns](IntroJavaScriptPatterns.md) in node.js. \n\nThe most up-to-date examples are:\n* [ExpressIntro](ExpressIntro) - this section contains a many examples using [express.js](https://expressjs.com), including:\n  * [FourLineServer](ExpressIntro/FourLineServer/) - a minimal static file server\n  * [staticPages](ExpressIntro/staticPages.js) - shows how to serve static pages as well as dynamic routes\n  * [getPost](ExpressIntro/getPost.js) - shows how to handle GET and POST requests, and how to handle json request data and form-urlencoded data\n  * [getPostPutDelete](ExpressIntro/getPostPutDelete.js) - shows how to use express.js .all() function to listen for any type of request (GET, POST, PUT, DELETE)\n  * [requestHeaders](ExpressIntro/requestHeaders.js) - shows how to get the raw headers of an HTTP request\n  * [restParameters](ExpressIntro/restParameters.js) - shows how to read RESTful parameters from the route of a request. \n  subroutes\n  * [fileUploader](ExpressIntro/fileUploader.js) - shows how to use multer.js to make a web page that can upload files to your server. \n  routes\n  * [subroutes](ExpressIntro/subroutes.js) - shows how to handle different RESTful subroutes\n* [glitch-examples](glitch-examples/) - these are examples for express.js, mqtt.js, websockets using ws.js, and  node-fetch.js  that I've posted on [glitch.com](https://glitch.com/@tigoe). Some of these duplicate the express intro examples above.\n* [HTTPS server](HttpsServer) - shows how to use express to respond to HTTPS requests. \n* [SerialIntro](SerialIntro) - a few examples showing how to use Serialport.js\n* [NodeWithNginx](NodeWithNginx/proxy-server.js) - a minimal proxy server to combine with nginx. \n  \nThere are other examples in the [main directory](/) as well. \n\n\n## Creating a node.js Project\n\nNode.js runs in a command line interface. You can edit your files in any editor you want. A typical node.js project has the following structure:\n\n* ``ProjectDirectory/``\n  * ``main_script.js``    - your main JavaScript program\n  * ``package.json``      - a manifest of dependencies\n  * ``package-lock.json`` - describes any changes that need to be made to package.json\n  * ``public/``           - a directory for static files\n    * ``index.html``      - static files to be served\n    * ``style.css``\n    * ``script.js``\n\nTo make a new project, create a directory for it, then create a main script file, which is usually a server, then use npm to install any libraries you know you'll use and initialize a package decription called `package.json`. For example, if you were making a project using express.js to make a web server, you'd start the project like so:\n\n````sh\n$ mkdir project-dir \n$ cd project-dir\n$ touch server.js\n$ npm install express\n$ npm init\n````\n npm will ask you a series of questions to fill out the package description, then it will generate two files, `package.json` and `package-lock.json`, and a directory, `node_modules`.  The first, `package.json`, is your project description, and the second,`package-lock.json`, describes any changes that need to be made to `package.json` or `node_modules`. The directory `node_modules` is where npm downloads the libraries that you install, and any other dependencies. The two files, `package.json` and `package-lock.json`, should be included in any repository in which you store your files, so that the project can be recreated. \n\n## Installing an Existing Project\n\n To re-create a project downloaded from a remote repository change directories into the project and use npm to install the dependencies. If `package.json` and `package-lock.json` exist, the command `npm install` will read them and install all needed dependencies into `node_modules`. \n\n## Running a Project\n\n Once you've got everything installed, you can run a project from the command line with the main script's name like so:\n\n ````sh\n$ node server.js\n ````\n\n Type control-C to stop the project. If you need to run it in the background for as long as the host is running, consider using [PM2](https://pm2.keymetrics.io/docs/usage/quick-start/). \n\n## Running on Glitch.com\n\nIf you'd like to run these on [glitch.com](https://www.glitch.com) or [heroku](https://www.heroku.com/) or another node.js host, you may need to change the port number to comply with whatever port the platform runs your scripts on. On glitch.com, you can use:\n\n````js\nprocess.env.PORT || portnumber\n````\n\nin place of the port number given in these scripts. Some of them have been adjusted accordingly. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftigoe%2Fnodeexamples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftigoe%2Fnodeexamples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftigoe%2Fnodeexamples/lists"}