Skip to content

Instantly share code, notes, and snippets.

@kunxin-chor
Created March 11, 2024 02:33
Show Gist options
  • Save kunxin-chor/66156224e3ee16db09c34b968f140e05 to your computer and use it in GitHub Desktop.
Save kunxin-chor/66156224e3ee16db09c34b968f140e05 to your computer and use it in GitHub Desktop.
RESTFul API Template
// 1. REQUIRE DEPENDENCIES
const express = require('express');
const mongodb = require('mongodb');
const cors = require('cors');
const app = express();
// enable the use of JSON
app.use(express.json());
// enable CORS
app.use(express.cors());
// 2. SETUP ROUTES
app.get('/api', function(req,res){
res.send("API is running");
})
// 3. ENABLE THE SERVER
app.listen(3000, function(){
console.log("Server has started");
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment