Introduction
...
Info |
---|
A quick over of three ways to create a node.js application |
Creating an Application Base
Method 1
Simply create your .js files and a launch.json file.
...
Code Block | ||||
---|---|---|---|---|
| ||||
var express = require("express"); var app = express(); app.listen(3000, () => { console.log("Server running on port 3000"); }); |
When you run this app you will see the message "Cannot GET /". If you check the developer's tools console output you will see the following error "GET http://localhost:3000/ 404 (Not Found). You are seeing this message because you have not set up any event handlers (your application has no endpoints)
Info | ||
---|---|---|
| ||
If you want to use import * as module from "module_file" add
When you switch to modules, require(...) will not be usable, see https://stackoverflow.com/questions/62488898/node-js-syntaxerror-cannot-use-import-statement-outside-a-module |