Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Nodejs code snippetsNew to Visual Studio Code? Get it now.
Nodejs code snippets

Nodejs code snippets

Harsh Dobariya

|
2,389 installs
| (0) | Free
A simple NodeJS snippets for developing fast nodejs API
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

a# NodeJS Code Snippets

The essential collection of Nodejs snippets.

Author

@ Harsh Dobariya

Features

Only what you need and nothing more.

Simply, simple Nodejs snippets.

These snippets were selected carefully from my own day-to-day NodeJS use. Not everything in NodeJS is included here. This is a hand selected set of snippets that work the way that you would expect, not just a copy of the documentation.

Usages

Usage

NodeJS Snippets

Snippet Renders
requ create require statement
exstatic Express set the static folder
exue Express URL encoded
exjson Express set to use json
ergr A router based get route
erpr A router based post route
esgr A simple based get route
espr A simple based post route
exs Express simple Hello world server Setup
exr Express routes for server
mongodbc MongoDB database connection
mysqlc MySQL database connection
gns Define schema of data in API
pass Defining passport strategy
mails Sending mail to user
dbug Generating debugging variables

Swagger Snippets

Snippet Renders
swbi Swagger basic info
swsi Swagger server info
swtg Swagger Tags
sws Swagger Security Schema
swscs Swagger String Schema
swsco Swagger Object Schema
swpath Swagger Path

NodeJS Full Expansions

exstatic - Express set the static folder

app.use(express.static("public"));

exue - Express URL encoded

app.use(express.urlencoded({ extended: false }));

exjson - Express set to use json

app.use(express.json());

esgr - A simple based get route

app.get("", (request, response) => {});

espr - A simple based post route

app.post("", (request, response) => {});

exs - Express simple Hello world server Setup

const express = require("express");
const app = express();

app.get("/", (req, res) => {
    res.send("Hello world");
});

const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`Server is running on...http://localhost:${port}`));

Swagger Full Expansions

swbi - Swagger basic info

module.exports = {
    openapi: "3.0.0",
    info: {
        version: "1.0.0",
        title: "",
        description: "",
        contact: {
            name: "",
            email: "",
            url: ""
        }
    }
};

swsco - Swagger Object Schema

module.exports = {
    components: {
        schemas: {
            Error: {
                type: "object",
                description: "error object",
                properties: {
                    error: {
                        type: "string",
                        description: "error message",
                        example: "NOT_FOUND"
                    }
                }
            }
        }
    }
};

Thank You! ❤️

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft